Endareth
Endareth

Reputation: 512

When using Asset Catalogs, is it possible to load images from a specific folder?

I'm attempting to use an image Asset Catalog in Xcode 5 for the first time and running into some issues. Previously I'd just have the image folder (with subfolders) referenced/linked into the project, and pass a full pathname to +[UIImage imageWithContentsOfFile:] to access what I needed, but I thought I'd try and use an Asset Catalog with folders instead.

As background, I've got a set of 500 or so items, and several types of related images (icon, profile, and so on). My thought was to be able to have an "itemIcons" folder, "itemProfiles" folder, and so on, within the Images.xcassets. Each folder would then have a asset simply referred to by a reference number (e.g. "001", "002", and so on). I was then planning on using +[UIImage imageWithContentsOfFile:] to load the required image file as needed (and I'm specifically after a non-caching loading method, so not using imageNamed). Unfortunately I can't seem to find any way to load the specific image from a specific folder.

I also am getting compiler warnings by doing this:

Asset Catalog Compiler Warning
The image set name "001" is used by multiple image sets.

Which seems to imply that I'm not going to be able to use Asset Catalog folders for this purpose, and will either have to go back to using external referenced images.

So, is it possible to load images programatically from a specific folder in an Asset Catalog?

Upvotes: 2

Views: 1171

Answers (1)

Lord Zsolt
Lord Zsolt

Reputation: 6557

Using asset catalog isn't the same as using imageWithContentOfFile:.

Images you store in your asset catalog are copied to the device at build time while images you load using imageWithContentOfFile are the ones you've saved to the Documents folder during runtime (ex: by generating an image or by downloading one).

You can create a specific structure in your Asset Catalog using folders and image sets, but you will be loading them using the imageNamed: method, thus two image sets can't have the same name.

Upvotes: 3

Related Questions