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

Jeffery Thomas picture Jeffery Thomas · Oct 12, 2015 · Viewed 9.4k times · Source

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.

Answer

joseph picture joseph · Apr 2, 2016

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