5

Let's, I have a custom Swift Cocoa Touch framework, MyLog, which has a simple function called printLog(). I have another Swift project named HelloWorld in different workspace/location. Now I need to import the custom framework MyLog into project HelloWorld, so that I can call MyLog.printLog().

Project -> Targets -> Build Phases -> Link Binary With Libraries

does not show my custom library in the list. Moreover I don't just want to link my custom library, rather I want to import separately as independent library so that running changes in MyLog wont reflect in HelloWorld.

NB: Similar things I do in Android with adding custom_library.jar in lib.

Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256

2 Answers2

6

Finally I got the solution with below steps,

Steps

  1. Mark your custom MyLog project as Framework when creating
  2. Implement func printLog and build the project (successful build will create a /Product/MyLog.framework file)
  3. Copy the /Product/Mylog.framework file into HelloWorld project directory using Finder
  4. Follow, HelloWorld Project -> Targets -> Build Phases -> Link Binary With Libraries -> + -> Add Other (select MyLog.framework from HelloWorld/ directory)
  5. Follow, HelloWorld Project -> Targets -> Build Phases -> Embed Frameworks -> + -> Other (select MyLog.framework from HelloWorld/ directory)
  6. Build HelloWorld and enjoy!

Update 1

  1. If you don't find path, HelloWorld Project -> Targets -> Build Phases -> Embed Frameworks please check, HelloWorld Project -> Targets -> General -> Embedded Binaries in the later versions of xcode, which will do the same thing step-5 does.
Community
  • 1
  • 1
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
  • I dont see step 5 in project ... :( – Alok C Mar 01 '17 at 04:37
  • @Alix this was for previous Xcode version, you will get `Embedded Binaries` under general tab, which will do the same. Reference: http://stackoverflow.com/a/37690368/1084174 – Sazzad Hissain Khan Mar 01 '17 at 04:46
  • my case is that framework is being generate in same workspace. so I dont need to put anything in the bridging-header.h. I can just import it, correct ? – Alok C Mar 01 '17 at 04:57
  • 1
    that worked but I have one objc lib, what would be correct place to add it as bridging header not able to find it ? thanks a lot for updating the answer. – Alok C Mar 01 '17 at 05:05
  • 1
    This pointed me to the right direction. I was able to solve the problem I was having. Kudos – Eric Aig Jul 07 '21 at 07:20
1

add the frameworks to "Embedded Binaries" (Target > General > Embedded Binaries) then run

priya
  • 69
  • 2