On May 20, 2015, at 3:04 PM, Alex Zavatone <z...@mac.com> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to