Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing pure Swift custom framework into other Swift project

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.

like image 703
Sazzad Hissain Khan Avatar asked May 09 '16 05:05

Sazzad Hissain Khan


People also ask

How do I import a framework?

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".

How import OBJC framework in Swift?

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.

How do I add a framework to a project in Xcode?

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.

How do I add a framework in Swiftui?

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.


2 Answers

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.
like image 168
Sazzad Hissain Khan Avatar answered Nov 15 '22 08:11

Sazzad Hissain Khan


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

like image 27
priya Avatar answered Nov 15 '22 08:11

priya