6

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.

wigging
  • 8,492
  • 12
  • 75
  • 117
  • As per [docs](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSImage_Class/Reference/Reference.html#//apple_ref/occ/clm/NSImage/imageNamed:) its a recursive search which includes your app bundle by default. – GoodSp33d Jun 15 '14 at 15:42
  • @GoodSp33d So how would I specify an item in a particular folder? For example, if two items have the same name but are in different folders, I would like to get an item from a particular folder. Otherwise, the search would just return the first (or last) item by the specified name regardless of where it is located in the app bundle. – wigging Jun 15 '14 at 19:21
  • Hmm... does it even allow you to name them the same? **EDIT** hmm... yep it does. – Fogmeister Jun 16 '14 at 16:01
  • it think it was a bug in Xcode 5 and fixed in 6 beta. when I try to add images with same name instantly rename second one to image-1... Edit ok if second one in a folder it allows. – modusCell Jun 16 '14 at 23:57

2 Answers2

0

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)

0

After a lot of searching , there are no way , as frozendevil, for that and the only possible way is to not using Images.xcassets at all and use the following method as described here Can I access all images in a .xcassets at once?

Community
  • 1
  • 1
Mohamed Saleh
  • 2,881
  • 1
  • 23
  • 35