With iOS 8, Apple has given us the ability to create dynamic frameworks for iOS, something that has always been availible for OS X. Apart from the fact that your app and extensions can share the same code, Apple is encouraging developers to share code between iOS and OS X. Apple’s describes an example of how to do so in its WWDC 2014 Session 223 video. The problem with the described steps is that it will build two separate targets, which normally wouldn’t be a big deal, except for the following inconveniences:
2 separate framework targets always have to keep their sources and dependencies in sync
2 separate testing unit bundles are required and also need to keep their sources and dependencies in sync
Code that will use your framework that will also build for iOS and OS X will require import statements like:
Because I found using compiler directives clumsy, through a lot of trial and error I discovered how to make a dynamic framework compile for iOS and OS X, as well as have a single universal test unit bundle. I mainly developed this process for NetworkObjects, but since then I’ve submitted merge requests for frameworks I use like ExSwift and CocoaLumberjack.
###1. Change the project’s valid architectures and supported platforms.
This should change your framework’s and test unit’s valid architectures and supported platforms as well. If not, then manually change them to inherit from the project’s build settings.
Base SDK: I recommend OS X, but it will work with iOS too. Note that with with iOS as the base SDK, “My Mac” target is separated into 3 different targets.
macosx iphoneos iphonesimulator
arm64 armv7 armv7s i386 x86_64
###2. Change the search paths for the Unit Test bundle
Runpath Search Paths:
$(inherited) @executable_path/Frameworks @loader_path/Frameworks @executable_path/../Frameworks @loader_path/../Frameworks
Framework Search Paths:
As long as your framework’s code and dependencies (like Foundation & CoreData) will run on both iOS and OS X, this process can be applied to any framework written in Objective-C or Swift. If you have any questions, you can contact me on Gitter.