I noticed a difference between the way I code (badly 😉 ) and the code I see from others.
Can anybody explain why I see some people using
self.varname.anotherpropertie
When
varname.anotherpropertie
Seems to work just as well. I dont use self. a lot in my code. I’m wondering is this very bad or is there something that I need to learn to understand why its used so much by most people?
Thanks again,
-Code
They are different things. In a class where you have an instance variable named
foowith a declared property also namedfoo, writing simplyfooaccesses the instance variable whileself.foogoes through the getter method for the property (which might just return the instance variable or it might do more).I’d suggest taking a look at the Declared Properties chapter of Apple’s The Objective-C Programming Language for a full explanation of how it works and when to choose which option.