Re: self.property vs. ivar of same name?
Re: self.property vs. ivar of same name?
- Subject: Re: self.property vs. ivar of same name?
- From: David Duncan <email@hidden>
- Date: Sat, 8 Mar 2008 11:54:04 -0800
On Mar 8, 2008, at 11:29 AM, Rick Mann wrote:
I was mucking about with some sample code. It had a property
"window" that was synthesized using @property, and an ivar of the
same name. The code referred to it using "self.window =". Since I
generally dislike using "self" or "this" unnecessarily, i removed
the "self.", thinking it would still work, but it didn't.
Define "didn't work" - there are quite a few shades of gray in didn't
work :)
Why is that? I get that "self.window =" is calling the synthesized
setter method, but "window =" should have just assigned to the ivar
and all should've been the same, right? The property was declared
with (nonatomic, retain).
Mostly. Both ways will set the ivar. Calling a setter however can have
other side effects above and beyond that (which are specified by the
property declaration).
Is the difference that using the property caused the retain count to
go up by one? I'll try the experiment, but I'd sure like confirmation.
Yes, the property in question (declared nonatomic, retain) will retain
what ever you hand it (and release what was previously set). The
properties documentation describes these combinations and what they
mean. <http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_5_section_1.html
>
--
David Duncan
Apple DTS Animation and Printing
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden