Convert a static library target into a framework target in an Xcode project

11,065

Solution 1

To convert the static/dynamic linked framework from static linked library,

  1. Add a new cocoa touch framework as a TARGET in your existing static linked library project.
  2. In the Build Phases, adding all the .m, .mm, .c, .cpp, .metal, etc. into "\Build Phases\Compile Sources" phase of your static linked framework target.
  3. Put the headers that you want to exposed in to "\Build Phases\Headers".
  4. For dynamic linked framework, remember to check the Mach-O Type setting in your Build Settings. If you are going to use swift, you need to make sure the Mach-O type is set as dynamic library so that it will become a dynamic linked framework. For static linked framework, you'll need to set the Mach-O type as static library, but you cannot use swift in the converted static linked framework (only objective-c, objective-c++, C++, C, etc. are allowed).

Then for the app that wants to use this framework just need to include the headers as #import and add the framework into "Build Phases\Link Binary With Libraries" of your App Target. If the converted framework is dynamic linked framework, you will need to put it into "Embedded Binaries".

Solution 2

I saw that someone created the framework manually, creating a module.framework file and copying all the header files in a module.framework/Headers folder. This solution seems to work, the project can import correctly the files and see them as a framework correctly.

I'm not sure this is the best way to do it tough, I'm trying it on a big project that ATM is importing the static library through cocoapods, but it seems like I have some problem with the visibility of some of the classes using the framework.

Share:
11,065
Jeffery Thomas
Author by

Jeffery Thomas

Updated on June 18, 2022

Comments

  • Jeffery Thomas
    Jeffery Thomas almost 2 years

    I have a an Xcode project which produces a static library. My team plans all new development in Swift. It is not possible to add Swift files to the static library project. We are dropping support for iOS 7, so it is now possible to include frameworks in our iOS app. Therefore, I intend to convert my static library project to a framework project.

    I have looked but I cannot find any tools or advice for how to perform this conversion. The static library is large (more than 100 .m files).

    I'm hoping for a better answer than create a new parallel framework target. I've attempted this twice. The first time as a swift target, but I wasn't able to easily import all the Objective C files. Next, as an Objective C target, but there is no .pch anymore.