Search code examples
objective-ccocoauiimagexcode5nsimage

Refer to an image in folder of Images.xcassets


I have the following structure in my Images.xcassets in Xcode:

enter image description here

There is the typical method to set the image using NSImage *image = [NSImage imageNamed:@"confused"]; but is there a way to set the image by using the folder structure?

For example, I tried NSImage *image = [NSImage imageNamed:@"/Statusbar/confused"]; to refer to an image in the Statusbar folder, but it does not work. This approach would be useful if you need to have different images with the same name where each image is located in a different folder of the xcassets. And yes, Xcode does let you name two images with the same name.


Solution

  • No, this is not possible. If you'd like to see this capability added please file a Radar. (I've personally filed rdar://15347004, "Add ability to introspect asset catalogs", for this problem—but the more radars the more likely it is that the issue will be noticed and addressed)