Re: NSColor Unable to be stored?
Re: NSColor Unable to be stored?
- Subject: Re: NSColor Unable to be stored?
- From: Pelle Johansson <email@hidden>
- Date: Wed, 30 May 2001 09:49:51 +0200
On onsdag, maj 30, 2001, at 05:52 , John Stringham wrote:
Hi all,
Although I'm fairly sure this question must've been answered before I
can't
find the answer in either Apple's documentation or other sites, so I'm
afraid I'm going to have to ask one of those patented "Dumb Questions":
Is it impossibly to store a NSColor in memory? What I've done is
basically
the following: I declared
NSColor *storedColor;
In an object's header file. Afterwards, I put the function:
storedColor = [NSColor colorWithDeviceRed:1.0 Green:1.0 Blue:1.0
Alpha:1.0];
in the object's init function (obviously not with those values,) and
then
finally in the object's drawRect function:
[storedColor set];
Now this seems pretty simple to me, and I cannot for the life of me
understand why it won't work. I get an error saying "NCSFString -set:
selector not recognized" or something similar. Is this a special case,
or am
I missing something obvious? Any help is appreciated.
Whenever you get that message you can almost be sure you forgot to
retain the variable.
Just do this in init:
storedColor = [[NSColor colorWithDeviceRed:1.0 Green:1.0 Blue:1.0
Alpha:1.0] retain];
And in dealloc:
[storedColor release];
If you're not sure about retaining and the garbage pool you should
probably take a look at some Cocoa tutorial.
--
Pelle Johansson
<email@hidden>