UIImage imageNamed returns nil UIImage imageNamed returns nil ios ios

UIImage imageNamed returns nil


There are only a few reasons why an image would come back nil with imageNamed:

  • The image is not in your bundle. Make sure the image is actually in your project. Make sure the target is checked by clicking on the file and selecting the target it belongs to.

  • You have the image name spelled incorrectly or a problem with the extension.

  • You are using a retina display but do not have an @2x image. Try changing your simulator to retina and see if it shows up.

  • If you are using an asset catalog make sure you have the correct devices selected in the attribute inspector.

Some tips:

If you are testing using simulator delete the app off of your simulator and clean your project, then re-run. If it still shows up it should show up on your phone (if it doesn't it's probably an issue with the case of the filename or the @2x version).

If you are testing on your phone and it doesn't show up, make sure you are using the same version of the simulator (if you have an iPhone 4/4s make sure to use the 4/4s simulator with retina).

One last thing according to this post: JPG image doesn't load with UIImage imageNamed There is some issue with certain JPG types working with imageNamed and no extension. IMO, you should be using PNGs anyway since iOS compresses them for you, unless you just have to use JPG.


Re Mike Weller's comment. The checkbox is ....

enter image description here


In my case, the PNG was malformed.

For some reason Xcode preview shown it correctly, but when I tried loading it with UIImage, it returned nil.