Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
- Subject: Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
- From: Ken Thomases <email@hidden>
- Date: Wed, 20 May 2015 15:22:23 -0500
On May 20, 2015, at 3:04 PM, Alex Zavatone <email@hidden> wrote:
> Many times in the classes, an ivar is defined in the @interface of the class. Sometimes not. Then sometimes, the same name of the ivar is used in the class and defined as a property and @synthesized.
>
> Sometimes not.
> Now, I remember back in 2012 that I could access a property within an instance of the object without using self, but never knew if I was accessing the ivar or the property itself simply by looking at the object.
You are accessing a property if you use explicit message sending ([someObject someProperty] or [someObject setSomeProperty:someValue]) or if you use implicit message sending view dot syntax (someObject.someProperty).
Anything else is direct access to the instance variable. That can be a naked reference to the variable name in a method (e.g. someProperty or _someProperty), in which case it's implicitly a field of self, or it can be an explicit field access with the arrow operator (e.g. someObject->someProperty or someObject->_someProperty).
In all of the above, someObject could be "self" or any other object pointer. Whether an instance variable has a leading underscore or not depends on exactly how the class was coded (whether and how the property was synthesized).
The fact that the instance variable is named after the property it backs does not make it the property.
> Sure, if there was a 'self.' in front of the object instance, I knew it was the property. But in the case(s) I have today, I'm looking at inconsistently cased instance variables (some properties) and nowhere are any preceded by 'self.' within the object instance, yet in the debugger's variable pane, these variables that look like ivars are all under listed under self.
>
> Wha?
Of course instance variables would be listed under self. Where else would they be listed? They are "inside" the object. That is, they are components of the object. So, they are listed under it hierarchically. The debugger will only ever list variables (including instance variables) in its variable list, never properties. Properties are methods.
Regards,
Ken
_______________________________________________
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