Reputation: 6479
Not sure how else to specify the path to the image.
I've added a png into a new image named "StatusBarIcon", which lives inside "Images.xcassets" resource folder.
I see they put a json file and what not.
Tried to do what the examples out there say, but no matter what I try, I always get nil as the output of [NSImage imageNamed:@"name of paths attempted here"]
Won't load using the full path either, I suppose the method is looking for the name of the image, but I've no idea how to specify the name correctly it seems, or perhaps I need another method?
Here are screenshots of my code, and my project.
Upvotes: 8
Views: 6079
Reputation: 9533
To load from the assets catalog of the current bundle, use something like:
let image = Bundle(for: type(of: self)).image(forResource: NSImage.Name(“logo"))!
Upvotes: -1
Reputation: 84
Make sure you have the project set to use xcassets instead of just individual resource files. Once you create an image in the xcasset, you should just specify the name of the image, not the path. For example, [NSImage imageNamed:@"StatusBarIcon"]
Upvotes: 3