我已经看到支持以 2 种通用格式(在各种书籍、博客等中)声明的属性的ivars :
myProperty = _myProperty;
myProperty = myProperty_;
苹果文档说,前一个是关键值合规所必需的
哪一个最合适?
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
Apple 目前的非正式建议是使用下划线前缀。有迹象表明,将来会有语法上的便利。