Apple documentation is not the best. One of our mobile apps requires display of images from multiple dynamic sources based on a list of precedence rules, prompting us to dig into Apple’s rules for image handling and priority. To save you time, here’s what we’ve found:
- [UIImage imageNamed:@”my_image”] will first check the .xcassets asset catalog. If that fails, it will fallback to searching for any embedded images in your project of the same name.
- [UIImage imageNamed:@”my_image”] will not scan any file system directories for images.
- [UIImage imageWithContentsOfFile:path] can be used for either images embedded in your app or ones saved into the device file system, given the correct path.
- The above functions will automatically take screen density into account. If you request “my_image.png”, they will automatically use “firstname.lastname@example.org” if appropriate and the properly named file is available.
Now to write some custom image handling based on top of these built-in rules…