I have a cocoapod library which contains assets in 2 formats:
my podspec
file contains the definition for the resource bundle:
s.resource_bundle = {'SparkSetup' => ['Resources/**/*.{xcassets,storyboard}']}
and I have a separate target in the pod project to create a resource bundle by using those files + a plist file for that bundle.
thing is that when I use the pod in an app project - I can see the storyboard/xcassets files being in the pod target and I can access and run the storyboard easily but the images referenced in the storyboard (to the .xcassets file) are not found in run-time (but displayed correctly in IB).
Error I get is:
Could not load the "spinner" image referenced from a nib in the bundle with identifier "(null)"
I do see a bundle file in the products directory. To instanciate VCs in the storyboard I use:
+(NSBundle *)getResourcesBundle { NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"SparkSetup" withExtension:@"bundle"]]; return bundle; } +(UIStoryboard *)getSetupStoryboard { UIStoryboard *setupStoryboard = [UIStoryboard storyboardWithName:@"setup" bundle:[SparkSetupMainController getResourcesBundle]]; return setupStoryboard; }
which seems to work well for finding the storyboard, but not for finding images in the .xcassets in the same bundle.
What am I doing wrong? how can I reference images from this storyboard/from code and be able to integrate this UI pod into any app?
Thanks!
Choose File > New > File. Choose Resource > Asset Catalog, and click Next. Give the asset catalog a name, choose a location, and click Create.
xcassets Catalog in Xcode. An asset catalog, simply put, is a single folder in Xcode that you use to organize your app's images, icons, colors, and more. Instead of adding individual images to Xcode's file organizer, you add assets neatly organized in a single catalog.
At least as of version 1.0.1 of Cocoapods, image asset catalogs are supported.
In my Swift 4.2 code, I used:
public static var GoogleIcon: UIImage { let bundle = Bundle(for: self) log.msg("bundle: \(bundle)") return UIImage(named: "GoogleIcon", in: bundle, compatibleWith: nil)! }
In my pod spec, I used:
s.resources = "SMCoreLib/Assets/*.xcassets"
When I build using the simulator, the .car file does show up in the Framework:
cd /Users/<snip>/SMCoreLib.framework ls Assets.car Info.plist SMCoreLib
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