I'm trying to modularize a large iOS project (being developed in Swift) using cocoa pods. The idea is to create "sub apps" complete with storyboards and assets which could be integrated into the main project.
I'm having troubles using storyboards in such a scenario. The issue is similar to (I think): https://github.com/CocoaPods/CocoaPods/issues/2597
Here is the .podspec of the module I'm trying to convert into a pod:
Pod::Spec.new do |spec|
spec.name = 'GlycoAppMenuModule'
spec.version = '0.0.8'
spec.license = { :type => 'MIT', :file => 'LICENSE' }
spec.homepage = 'https://google.com'
spec.platform = :ios, "8.0"
spec.authors = { 'Abdulla Contractor' => '[email protected]' }
spec.summary = 'Views for menu page'
spec.source = { :git => 'https://github.com/Holmusk/GlycoAppMenuModule.git', :tag => '0.0.8' }
spec.source_files = 'GlycoAppMenuModule/*'
spec.resource_bundles = {
'resources' => ['GlycoAppMenuModule/**/*.{lproj,storyboard}']}
# spec.framework = 'Foundation'
end
and here is the code I use to attempt to use the storyboard
let bundlePath = NSBundle(forClass: GANavigationMenuViewController.self).pathForResource("resources", ofType: "bundle")
let bundle = NSBundle(path: bundlePath!)
let storyboard: UIStoryboard = UIStoryboard(name: "Menu", bundle: bundle)
let vc = storyboard.instantiateInitialViewController() as! UIViewController
self.presentViewController(vc, animated: false, completion: nil)
this is the error I get
2015-06-05 11:39:40.365 temp[3593:50802] Unknown class _TtC9resources30GANavigationMenuViewController in Interface Builder file.
2015-06-05 11:39:40.370 temp[3593:50802] Could not load the "icAccount.png" image referenced from a nib in the bundle with identifier "(null)"
2015-06-05 11:39:40.371 temp[3593:50802] Could not load the "icConnect.png" image referenced from a nib in the bundle with identifier "(null)"
2015-06-05 11:39:40.371 temp[3593:50802] Could not load the "icDiabetesProfile.png" image referenced from a nib in the bundle with identifier "(null)"
2015-06-05 11:39:40.373 temp[3593:50802] Could not load the "icLogout.png" image referenced from a nib in the bundle with identifier "(null)"
2015-06-05 11:39:40.377 temp[3593:50802] Could not load the "icCircle.png" image referenced from a nib in the bundle with identifier "(null)"
2015-06-05 11:39:40.386 temp[3593:50802] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fb3f3d2cdd0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key accountButton.'
Any idea what I may be missing?
I had the same problem and I solved it.
In your .podspec the ONLY resource tag you need is:
s.resources = "MMA_Piece/**/*.{png,jpeg,jpg,storyboard,xib,xcassets}"
Now you might be asking: "Of course I have already tried this but it didn't work? Why should it work now?"
Well let me tell you :D
Make sure that EVERY resource you want to have included in your custom CocoaPod is inside your bottom level project directory. In my case (MMA_Piece project) this is the following folder (the selected one):
Done! If you use the pod in another project by using 'pod install' your resources will have come with it like so:
IMPORTANT: If you want to use the resource in your other project, say "MainProject", you will ALWAYS need to specify the bundle! Or "MainProject" won't be able to find the resource!
Hope this helps you out!
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