8

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. different attempts and log output showing it's always nil what my image is like

2 Answers 2

3

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"]

Sign up to request clarification or add additional context in comments.

6 Comments

tried hard not to ask this question, but how exactly do you make sure the project is configured to use xcassets? is it by making the "Images.xcassets" type "Default - assetcatalog" and Location "Relative to Group" couldn't find anything on google about this.
Put your own images in that folder? Why do you want to do that? Besides, what version of Xcode are you using? Xcode 6?
I dragged them using the user interface of XCode (didn't do it with Finder, nor the command line). Yes I'm using XCode 6. I've put a screenshot up there (2nd one) of how the image appears in the UI, i dragged and dropped it the on top of the blank slot/placeholder and named it "StatusBarIcon"
@Gubatron yup. If you go the project settings, you should be able to see your Targets. Select the app Target you are working on, then the General. In the App Icons section, what do you see there?
So @Gubatron you don't see an option there to use Asset Catalog? What I am curious is the validity of the toString method you are using. Can you you enable the breakpoint and step through the code. Check if after each assignment that the images are saying nil in there.
|
-1

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"))!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.