1

我已经看到支持以 2 种通用格式(在各种书籍、博客等中)声明的属性的ivars :

myProperty = _myProperty;
myProperty = myProperty_; 

苹果文档说,前一个是关键值合规所必需的

哪一个最合适?

4

2 回答 2

2

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

于 2012-01-30T21:58:14.837 回答
1

Apple 目前的非正式建议是使用下划线前缀。有迹象表明,将来会有语法上的便利。

于 2012-01-30T22:10:14.430 回答