I'm trying to make a framework that will bundle a storyboard. I have checked, and the created .framework includes my .storyboard file (as a .storyboardc
file), and have gotten the framework to load the storyboard at runtime. However, this being a framework, I'd like for the code to be as versatile as possible, and I feel like my current solution is a little hacky. Currently, I'm loading the storyboard using the following code:
let mainBundlePath: String = NSBundle.mainBundle().resourcePath let frameworkBundlePath = mainBundlePath.stringByAppendingPathComponent("Frameworks/AuthenticationManager.framework") let frameworkBundle = NSBundle(path: frameworkBundlePath) let storyboard = UIStoryboard(name: "Storyboard", bundle: frameworkBundle)
A couple of things I've noticed that could be gotchas:
Frameworks/
) could, potentially, change in the future, and should not relied upon?NSBundle
of the framework there's no way of getting the product name?There may be other issues, solutions to the above issues, or the above issues may not be issues after all, but I've not been able to think of them.
This question may be be more suited for Code Review, but I felt it'd fit in well here, too. If it needs to be moved over there, feel free to do that or tell me to do it.
Select the target for where you want to add frameworks in the project settings editor. 3. Select the “Build Phases” tab, and click the small triangle next to “Link Binary With Libraries” to view all of the frameworks in your application. 4.To Add frameworks, click the “+” below the list of frameworks.
A framework (created from the "Cocoa Touch Framework" template) has a bundle identifier, which is stored in the Info.plist of the generated framework bundle.
The bundle identifier is configured in the general target settings. By default, it is <organization prefix>.<framework name>
.
You can locate the framework using this identifier, for example:
let frameworkBundle = NSBundle(identifier: "com.duffy.AuthenticationManager") let storyboard = UIStoryboard(name: "Storyboard", bundle: frameworkBundle)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With