Clicky

iOS Dev Nugget 84 One More Thing About +imageWithContentsOfFile: vs. +imageNamed:

.

Need to run a code review on your codebase? Hire me

In #34: When do you use UIImage's +imageWithContentsOfFile: over +imageNamed:?, I mentioned the primary difference between UIImage +imageWithContentsOfFile and +imageNamed:. There is another difference, when using +imageNamed:, iOS will automatically search for the correct version of the image that is optimized for the platform, e.g. loading fileName@x.png if you had specify fileName.png when running on a device with retina display. On the other hand, with +imageWithContentsOfFile:, you have to specific the filename explicitly. iOS will not make any guesses to the proper variation of the filename to use.

Bonus nugget: the file extension is optional when using +imageNamed: with a .png file. i.e. [UIImage imageNamed:@"filename"] and [UIImage imageNamed:@"filename.png"] works the same way.


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues