Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
Hello
I am having some problems giving NSImage a file. Can someone tell me why I am getting this error?
'NSImage' may not respond to '-setImage:'

Here is my code:

Code:
NSImage *left;
[left setImage:[NSImage imageNamed:@"left.png"]];

Does anyone know why it is giving me this warning?
Help is appreciated
Thanks
 
Because there is no "setImage" message than can be sent to NSImage.

You simply want

Code:
NSImage* left = [NSImage imageNamed:@"left.png"];
 
Hello
I am having some problems giving NSImage a file. Can someone tell me why I am getting this error?
'NSImage' may not respond to '-setImage:'

Here is my code:

Code:
NSImage *left;
[left setImage:[NSImage imageNamed:@"left.png"]];

Does anyone know why it is giving me this warning?
Help is appreciated
Thanks

"left" is an uninitialised variable of type NSImage*.
You try to send a message to an uninitialised variable.
The compiler warns you because this is going to crash when you run the code.

I'd think about how I would initialise the variable.
 
"left" is an uninitialised variable of type NSImage*.
You try to send a message to an uninitialised variable.
The compiler warns you because this is going to crash when you run the code.

I'd think about how I would initialise the variable.

Really? Is your compiler that observant? I have not noticed that kind of warning from mine. (Then again, I have probably not made that mistake in a very long time.)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.