加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – Xcode 4在使用@属性时自动生成iVars,在哪里可以

发布时间:2020-12-14 17:18:21 所属栏目:百科 来源:网络整理
导读:我读过“ Xcode中的新功能”,但我找不到此功能的官方解释. 我在哪里可以找到官方解释?哪个文件?谢谢. 解决方法 您可以在 Objective-C Programming Language: Declared Properties的“财产实施指令”下的Apple文档中找到此信息.是否自动合成ivar取决于您使
我读过“ Xcode中的新功能”,但我找不到此功能的官方解释.
我在哪里可以找到官方解释?哪个文件?谢谢.

解决方法

您可以在 Objective-C Programming Language: Declared Properties的“财产实施指令”下的Apple文档中找到此信息.是否自动合成ivar取决于您使用的运行时间:

There are differences in the behavior of accessor synthesis that depend on the runtime (see also “Runtime Difference”):

  • For the legacy runtimes,instance variables must already be declared in the @interface block of the current class. If an instance variable of the same name as the property exists,and if its type is compatible with the property’s type,it is used—otherwise,you get a compiler error.
  • For the modern runtimes (see “Runtime Versions and Platforms” in Objective-C Runtime Programming Guide),instance variables are synthesized as needed. If an instance variable of the same name already exists,it is used.

iOS总是使用现代运行时,因此您永远不需要显式声明ivars.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读