Using Custom iOS / OSX Frameworks

I’ve had many occasions where I’ve wanted to include internal frameworks in an iOS or OSX application 3dkib5x. Years ago (and still to this day on small projects – don’t judge :), I’d simply add the framework code into a separate folder in the application and compile it directly into the application itself.

Of course, I inevitably came across another project which needed to use the library or a few classes from the library, I’d turn my head, close my eyes, copy the files from one project to another, and tell myself I did the right thing, again, in the name of pragmatism.

And then I’d run across a bug.

I tried to to the right thing, honest!

The idea of compiling all framework code directly into an application has never sat well with me. Coming from a C# background at Microsoft and Java at Code42, or like anyone who passed CS 101, I was trained to factor code into projects. Even if they are not used on other applications, it’s clean and reduces mental overhead to simply factor code into appropriate projects right from the start.

But working with libraries and frameworks on iOS has been a pain over the years. iOS didn’t support dynamic libraries (frameworks) until iOS 8! They added support presumably for app extensions. Before frameworks, we had to use static libraries, make sure header files were in their appropriate locations, and setup your build settings appropriately. Getting the build settings right on an iOS app w/ dependencies has cost me man months across all my projects. It’s not trivial, clang gives cryptic error messages, and finding the right combination of settings is not easy to Google.

Apple, in my opinion, doesn’t encourage or document library/framework usage well. Thankfully the community has came to Apple’s rescue in the form of CocoaPods – a package manager for including frameworks into your objc / swift applications. Use CocoaPods! Publish your libraries to CocoaPods! If you don’t want or can’t publish your libraries to CocoaPods, you’re stuck managing your own framework look at this web-site.

Sample Code

To help myself (and developers) out, I created a dead simple OSX project that includes a Framework, which itself includes a Framework just for the recursive heck of it.

I posted the sample project to github here – OSX Framework Example.

This may prove risky – but if you want help adding a framework to your iOS or OSX project, hit me up on twitter – @damonallison – and I’ll give you a hand setting things up.

Comments are closed, but trackbacks and pingbacks are open.