In a nutshell :
How can I load images from a compiled Assets.car
within an NSBundle
?
Full Version:
I'm in the process of converting a suite of apps to use CocoaPods
. Each app relies on a shared pod called Core
.
Core
includes code files, xib
files, and several xcasset
files.
Here's the relevant line from the Podspec
for Core
that creates the resource bundle:
s.resource_bundles = {'CoreResources' => ['Core/Resources/*']}
The Podspec
passes pod spec lint
, and main project that relies on it correctly builds.
However, none of the images from any xcasset
files within Core
are showing.
I am (naively) trying to load the images using a category on UIImage
like this:
@implementation UIImage (Bundle)
+ (UIImage *)imageNamed:(NSString *)name bundle:(NSBundle *)bundle
{
if (!bundle)
return [UIImage imageNamed:name];
UIImage *image = [UIImage imageNamed:[self imageName:name forBundle:bundle]];
return image;
}
+ (NSString *)imageName:(NSString *)name forBundle:(NSBundle *)bundle
{
NSString *bundleName = [[bundle bundlePath] lastPathComponent];
name = [bundleName stringByAppendingPathComponent:name];
return name;
}
@end
Previously, Core
was a submodule
, and this solution worked fine. However, upon inspection of my previous bundle
file (separate from main
bundle), I noticed that all of the images were simply being copied into the bundle
... i.e.
Image.png
, [email protected]
, etc were all in the bundle.
Upon inspection of the CocoaPods
-generated bundle, it contains an
Assets.car
which I understand to be a combined, compiled version of all the xcasset
files within said Core
subdirectory.
How can I load images from this compiled Assets.car
within this Core
resources bundle?
As a hack, I suppose I could...
The Podspec syntax reference gives this as an example:
spec.resource = "Resources/HockeySDK.bundle"
This seems to suggest that it's possible to create the bundle manually within Xcode and have CocoaPods simply copy it.
This is more of a hack than a solution, though.
I believe CocoaPods (v 0.29+) can handle this entirely...?