I keep seeing things like this in example Objective C code:
_myProp = newValue;
As far as I understand, creating a property myProp
will create the actual variable as _myProp
, and two accessor methods which are (by default) myProp
(the getter) and setMyProp
(the setter).
My question is, why do I keep seeing example code that by-passes the accessor methods and gets at the variable directly? Is there any advantage to this?
There are occasions where you don't want to declare a property and instead just use a private ivar.
If, on the other hand, there is a property declaration there should be no reason to directly access the ivar, except in the implementation of the accessors.
Sometimes people want to bypass the side effects of accessors and use the ivar directly. This is usually a sign of an architectural flaw, though.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments