Reputation: 93
I have seen ivars that are backing properties declared in 2 general formats (in various books, on blogs, etc...) :
myProperty = _myProperty;
myProperty = myProperty_;
Apple docs say the former one is needed for key value compliance
Which one is most appropriate ?
Upvotes: 1
Views: 344
Reputation: 14558
The currently informal recommendation from Apple is to use an underscore prefix. There are indications that there will be syntactic conveniences for this in future.
Upvotes: 1
Reputation: 237080
If you're creating a property, the name of the underlying ivar doesn't make any difference to KVC — it will go through the accessor. It will only access the instance variable if both of the following are true:
It can't find any appropriate accessor for the key
The object's class returns YES
for accessInstanceVariablesDirectly
Upvotes: 2