Re: I'm having trouble retaining a NSColor
Re: I'm having trouble retaining a NSColor
- Subject: Re: I'm having trouble retaining a NSColor
- From: Matt Neuburg <email@hidden>
- Date: Tue, 29 Aug 2006 10:09:54 -0700
- Thread-topic: I'm having trouble retaining a NSColor
On Mon, 28 Aug 2006 18:36:47 -0400, "Alan Smith" <email@hidden>
said:
>Thanks everyone but I might want highlightColor to equal nil.
But as I said to you in my earlier note, the way your original code runs,
highlightColor will *never* be nil. That's part of the problem (though, to
be sure, it is not the problem you asked about). The way your code is
written, if you try to pass nil, you release the ivar but you don't set it
to nil. Bad idea!
Maybe part of the problem is that you don't understand what a pointer is or
what "release" means. Here's the deal.
[myIvar release] means: myIvar is pointer to an object. Reduce the retain
count of that object.
Now, myIvar is still a pointer, so if reducing the retain count causes the
object to vanish, myIvar is now a pointer to junk, and referring to it will
probably crash your program.
To avoid this badness, you can then say myIvar=nil. Now at least it is safe
to refer to myIvar. But your code never does that.
> I will read those docs but the problem currently remains. What do you
> mean by "accessors"?
Ah. This could be the another part of the problem.
Look, in Xcode, type this phrase:
NSString* s;
Now select it and chose [Scripts] > Code > Place Accessor Defs on Clipboard.
(The [Scripts] menu looks like a black scrolled "s".)
Now paste.
That is an accessor, and that is how to write an accessor. It is a fairly
reliable pattern for getting and setting the value of an instance variable.
Do it that way unless you know *exactly* why not.
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden