I'm trying to create a Pod using CocoaPods and I want to bundle a "Demo" Storyboard that I can reference to from the Main Storyboard from my example application. The problem is that Xcode gives me the following compiler error when I do so:
Did not find storyboard named "Demo" referenced from Main.storyboard
See:
In my Podspec, I included:
s.resource_bundles = {
'StoryboardAssets' => ['Pod/Assets/*.{storyboard,png}']
}
You can find the demo repository that I created using the "Using Pod Lib Create" guide, you can find it here:
https://github.com/Kukiwon/StoryboardDemo
I'm running CocoaPods version 0.39.0.
So what would be the proper way to reference a Storyboard from your Pod? Am I missing something?
Files included in a Dynamic Framework are embedded in a different NSBundle
in the application. To make it easier to obtain the storyboard, you can create a helper class inside your library:
public class StoryboardHelper: NSObject {
public static let helper = StoryboardHelper()
public lazy var storyboard: UIStoryboard! = UIStoryboard(name: "Main", bundle: NSBundle(forClass: StoryboardHelper.self))
public func rootController() -> UIViewController! {
return storyboard.instantiateInitialViewController()
}
}
NSBundle(forClass: StoryboardHelper.self)
will obtain the bundle of StoryboardHelper
.
This way, your user only needs to do the following to show your root view controller of the embedded storyboard:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window?.rootViewController = StoryboardHelper.helper.rootController()
window?.makeKeyAndVisible()
return true
}
To reference storyboard using cocoapods, you should set in the Bundle section, the bundle identifier of the pod, like the picture below:
And in your podspec file, you should add the reference of your storyboard (as resource and not bundle)
s.resource = 'MyPod/MyStoryboardName.storyboard'
After the pod update, everything will work as expected
Hope that helps
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