0

I have a swift project just like the one the picture I have given. There is a framework on it. The framework is written in objective C(Also some pure c++ code). I successfully imported the framework into swift project and tested some functionality. Notice, there are also 2 objective c files in the project.(naming linker.h and linker.m)

I can call the api in the framework via swift. But the problem is, from objective c none of the api is accessible. I can call nothing from the objective c files(linker.m). The objective c files cannot even find the framework.

Now why do I need to call from objective c if I can call directly from swift? Because some of the api are purely written on C++. The associated implementation file is X.mm. Now according to the documentation of apple I cannot call them directly from swift.

I searched SO and found that I have to create a objective c wrapper for swift. The problem is I cannot call or import the framework in objective c files (linker.m and linker.h). How to do that? Any tutorials or materials should I follow?

I hope the question is understandable.

enter image description here

Shubhashis
  • 10,411
  • 11
  • 33
  • 48
  • How did you try to import the framework into your Objective-C files? Did you use an import statement in your wrapper (`linker`) files? Another thing is that the wrapper that calls C++ code should be Objective-C++, i.e. in `.mm`, not `.m`, files. The functions you intend to call from Swift cannot have parameters or return values of C++ types, but implementations of those functions can use C++ types. – Anatoli P Jul 13 '16 at 02:14
  • The following might help regarding the wrapper: http://stackoverflow.com/questions/38157689/calling-objective-c-parent-from-c-object/38278299#38278299 And this: http://stackoverflow.com/questions/37413951/video-processing-with-opencv-in-ios-swift-project/37427098#37427098 – Anatoli P Jul 13 '16 at 02:15
  • Thank you @OmniProg. modifying the .m file to .mm file and adding all the headers solved it. – Shubhashis Jul 13 '16 at 05:10

0 Answers0