Some days ago i wrote a post to announce that my DownPicker component library just became available on CocoaPods. Shortly after the pull of the refactoring I made to make everything compliant with the CocoaPods public trunk interface, some users noticed that the component - only when installed as a pod using the pod install command - was unable to properly display the embedded images. A strange behaviour indeed, since I had them included in the /Assets/ folder, which path is obviously included in the wildcard reference i set to the resource_bundle property of the .podspec file:
1 2 3 |
s.resource_bundles = { 'DownPicker' => ['DownPicker/**/*.*'] } |
After a quick check it turned out that the issue was related to the component code itself: the method I used to reference my image wasn't referencing any bundle, expecting the resource files to be in the root path.
1 |
[self setArrowImage:[UIImage imageNamed:@"downArrow"]]; |
This is something that would work on a manually added component - such as it was until few days ago - but not for a CocoaPod.
Luckily enough, the fix was quite straightforward: all I had to do was creating a reference to the bundle itself and passing it to the imageNamed method using the additional overload which serves this exact purpose:
1 2 |
NSBundle *bundle = [NSBundle bundleForClass:[self class]]; [self setArrowImage:[UIImage imageNamed:@"downArrow" inBundle:bundle compatibleWithTraitCollection:nil]]; |
This small update can be used for any other asset / resource file not found, it won't break your existing code and it will work even for manual installations. If you're also facing a similar issue, chances are that it will save your day too.
Happy coding!
EDIT: just found this thread on StackOverflow containing an almost identical approach. You might want to check it out for future updates regarding this issue.