Swift frameworks with Optional feature frameworks
The idea of the setup shown is to prove on example, how to:
- Setup closed source frameworks with CocoaPods
- Utilize weak linking between them
- Make features that depends on whether the additional frameworks are linked or not
The project is composed of three parts:
Simple app, illustrating situation, where you can include one or more frameworks via CocoaPods.
When launched (only iPhone Simulator for now!) the screen would turn:
- green if AdditionalSDK is present
- gray if not
Pressing TEST button would print info to the console, using additional SDK features or not.
To enable/disable AdditionalSDK comment or uncomment line #7 in Podfile, and reload pods by executing "rake pods" from main app dir.
Shows how to setup frameworks (MainSDK + AdditionalSDK) in a way, that AdditionalSDK is optional, and the MainSDK would change behaviour depending on its availability.
- telling whether AdditionalSDK is available at all
- "safe" adopting AdditionalSDK protocols
- performing tasks differently, depending on additional features availability
To make weak link between frameworks, you can select optional in linked frameworks section:
Just a Container for "vendored_frameworks". They are compiled only for simulator now.
In the "final setup", when making similar setup to ship your frameworks, you'd probably be using fat binaries, so your users would be able to build for both devices and simulators.
Summary + Where to go from Where
It seems, that when using Objective-C, it is possible to take advantage of weak linking (and thus "optional" frameworks). It seems it is impossible though to do that with Swift only setup.
Potential Improvements: Currently, the MainSDK "Interop" objc files are public. You can make them "private", and still use from Swift, using these hints: