Re: Properties vs Instance Variables
Re: Properties vs Instance Variables
- Subject: Re: Properties vs Instance Variables
- From: David Duncan <email@hidden>
- Date: Wed, 27 Apr 2011 09:39:48 -0700
On Apr 27, 2011, at 9:09 AM, Joanna Carter wrote:
> I too would like to see a means of explicitly accessing the ivar, even if it has the same name as the property; although, I thought that not calling self.property from within the .m file defaulted to accessing the ivar if both it and a property existed?
Given:
@property(...) id foo;
@synthesize foo = _foo;
Then the following holds:
_foo and self->_foo are equivalent means of direct ivar access.
self.foo = bar and [self setFoo:bar] are equivalent means of setting the value of the property foo.
bar = self.foo and bar = [self foo] are equivalent means of getting the value of the property foo.
This remains true if you name the instance variable the same as the property, but is typically considered more confusing. That is, if you use "@synthesize foo", you can still access "foo" and "self->foo" identically to _foo and self->_foo above.
--
David Duncan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden