When Xcode auto-synthesizes a property, it automatically adds a supporting instance variable that has the same name as the property with a prepended _
. You don't need to manually specify the instance variable, it's automatically there.
Although self->_foo
compiles and seems to work, I have never seen anybody using this syntax to access ivars. I find it potentially confusing with the property syntax self.foo
, so I would avoid this notation completely. You can access the instance variable by directly typing _foo
if you want. But I would also avoid that, unless you are overriding or extending a property accessor method.
I would access the property solely through the property dot notation [1], which IMHO makes code more readable and handles the strong/weak/copy semantics that you specified when declaring the property.
- Using property dot notation is syntactic sugar for accessing the property through the auto-syhthesized
-(PropertyType)property
and -(void)setProperty:(PropertyType)property
methods