• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSColor Unable to be stored?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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>


  • Prev by Date: Re: BSD Cocoa GUI Examples - where?
  • Next by Date: Re: NSColor Unable to be stored?
  • Previous by thread: NSColor Unable to be stored?
  • Next by thread: Re: NSColor Unable to be stored?
  • Index(es):
    • Date
    • Thread