Possible Duplicates:
How does an underscore in front of a variable in a cocoa objective-c class work? Prefixing property names with an underscore in Objective C
Why do a lot of Objective-C programmers put underscores before instance variables (even if they never even access them directly anywhere from their code)? What's the logic behind that?
Prepending an underscore to instance variable names is a convention for all variables that aren't meant to be accessed outside of the class instance. This makes it clear to the developer (and the user of the code if it's in a library) what's intended to be accessed externally and what isn't.
The logic is to make it clear when accessing the property vs accessing the ivar.
You can't mistakenly access the raw ivar without the property if its underscored. I don't do this in my own code though.
精彩评论