7

Is there any way to retrieve a UIImage object with imageWithContentsOfFile: if the image is stored in an Bundle (Xcode 5 Image Catalog)?

It's easy to access it with the imageNamed: method, but imageWithContentsOfFile: has a slightly different behavior, so what do I pass in the path parameter?

I've tried to use a variety of formats, but they all return a nil value:

  • ImageName@2x.png
  • ImageName@2x
  • ImageName
  • NSBundle File Path to Image

Apple's documentation doesn't specify a format for this. Any ideas?

Sam Spencer
  • 8,492
  • 12
  • 76
  • 133

1 Answers1

2

You can't load an image from xcasset via imageWithContentsOfFile:, because every entry in xcasset is compiled into a single binary file Assets.car. The format of this file is not documented and yet not reverse-engeneered well afaik (see "What you should know if you want to try reverse-engineering this stuff." section for explanations).

This is done for performance and low memory consume reasons, that's why imageNamed: is a good solution.

Sega-Zero
  • 3,034
  • 2
  • 22
  • 46