Use Objective-C in Swift as a Library

338 Views Asked by At

I have a Swift project that uses a library called OpenTok. I need to use an Objective-C class that has the same dependency(OpenTok) in my Swift project. The problem is when I use the objective C file it imports all the unnecessary libraries into Swift Project.

My question is how I can use Objective C files in my project as libraries that point to the same dependencies as the app, so once the app imports my Objective-C libraries, there will be no conflicts such as "One of the two will be used. Which one is undefined." error.

1

There are 1 best solutions below

0
LeverkusenFan On
  1. Create a framework for your Objective-C files and Embed to your main project.
  2. The new objc framework should link the OpenTok as well.
  3. Insure the mach-type of objc framework and OpenTok is "Static Library".

If you import OpenTok as Dynamic Library, with this kind of dependency relationship, there will be two copies of OpenTok symbols in your app binary. So the "One of the two will be used. Which one is undefined." warning will appear when starting the App.