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

imageNamed non valido (e altri problemi con i resource files) dopo la creazione di un CocoaPod

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:

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.

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.

 

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. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.