Path Parameter in UIImage imageWithContentsOfFile: for XCAsset

3.3k views Asked by At

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:

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

1

There are 1 answers

0
Sega-Zero On

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.