Converting an Existing Project into Customizable Framework

Create a framework from existing iOS project

When you want to make a framework, or module, from a project, the first thing you’ll need to do is, if you don’t have one already, make an Xcode project workspace (File > Save as Workspace) . The next step is to add a new framework “project” to your workspace (that could’ve been why you saw some resources telling you to make a new project) with File > New Project and choosing Cocoa Touch framework. When you add it, make sure you pick your workspace under both Add to and Group. Then you will need to migrate in the files that you wanted to be in this module — make sure to choose copy items if needed.
Here’s an article with more specific details on the process if you need it:
https://medium.com/kinandcartacreated/modular-ios-splitting-a-workspace-into-modules-331293f1090

Integrate two massive apps as frameworks into one Xcode project

Too big for a comment, will post here. I did something like that in the past, and the steps were something like this:

Step 1: Turn each heavy app into light app + (heavy) framework within the same workspace.

Make your light app depend on heavy framework and get that to work. I would start from creating an empty framework, getting it as dependency to the app, and then gradually migrating classes - group by group, merging each group (even if it's not final).

You won't be able to migrate everything from the app, but it will tell you how you will have to integrate with that framework. For example things like entitlements, AppDelegate etc will remain in the App. But most of the code will be in the framework, buildable as a separate framework target.

Step 2: Once each app is converted, you can create a completely new app, drag & drop your frameworks into that app (to begin with, you can do something better later), and use code from both "light" apps to integrate with your frameworks.

You will need to bring all the pods, and may need to resolve some conflicts at this point too.

Step 3: Once your new app is working, you can figure out how you will actually deliver frameworks to that app: is it going to be private pod, or drag & drop, or anything else.

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

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



Related Topics



Leave a reply



Submit