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.
To embed your frameworks, you shouldn't use the build settings directly, but go to the General tab of the project editor for your app target (select the project item in the navigator, then select the target in the editor pane, then select the General tab). Add your framework under "Embedded Binaries".
The correct approach is as follows: Import your Objective C framework by dragging and dropping the framework into an Xcode 6 Swift project. Create a new Objective C file in your project (File->New->File [Objective C for iOS]). Accept the prompt (agree) to create a bridging header file between Objective C and Swift.
To include a framework in your Xcode project, choose Project > Add to Project and select the framework directory. Alternatively, you can control-click your project group and choose Add Files > Existing Frameworks from the contextual menu.
Create new Xcode project using the Framework template Let's begin by creating a framework in Xcode by selecting File > New > Project… from the menu bar. Continue by selecting Framework project template under the iOS tab. Then click Next. Finally name your framework, you can name it whatever you want.
Finally I got the solution with below steps,
MyLog
project as Framework
when creatingfunc printLog
and build the project (successful build will create a /Product/MyLog.framework
file)/Product/Mylog.framework
file into HelloWorld
project directory using FinderHelloWorld Project -> Targets -> Build Phases -> Link Binary With Libraries -> + -> Add Other
(select MyLog.framework
from HelloWorld/
directory)HelloWorld Project -> Targets -> Build Phases -> Embed Frameworks -> + -> Other
(select MyLog.framework
from HelloWorld/
directory)HelloWorld
and enjoy!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.add the frameworks to "Embedded Binaries" (Target > General > Embedded Binaries) then run
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With