imageNamed not found and other Assets/Resource Files issues after creating a new CocoaPod library

Some days ago i wrote a post to announce that my DownPickercomponent 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 podinstall 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:

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.

Post navigation

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies.

This site uses cookies to improve user experience, personalize content & ads, provide social media features and analyze our traffic: some of these info are shared with our social media, advertising and analytics partners. We assume you're okay with this, but you can opt-out if you wish. Read the Privacy Policy for further info.