• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ProgrammingwithObjective-C--属性的缺省实现

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Programming with Objective-C  -- 属性的缺省实现

 

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithObjects/WorkingwithObjects.html#//apple_ref/doc/uid/TP40011210-CH4-SW6

 

Properties Are Atomic by Default

By default, an Objective-C property is atomic:

 

Note: The opposite of readonly is readwrite. There’s no need to specify the readwrite attribute explicitly, because it is the default.

 

 

 

Most Properties Are Backed by Instance Variables

By default, a readwrite property will be backed by an instance variable, which will again be synthesized automatically by the compiler.

 

You Can Customize Synthesized Instance Variable Names

As mentioned earlier, the default behavior for a writeable property is to use an instance variable called _propertyName.

 

By default, both Objective-C properties and variables maintain strong references to their objects. This is fine for many situations, but it does cause a potential problem with strong reference cycles.

 

 

Use Strong and Weak Declarations to Manage Ownership

By default, object properties declared like this:

@property id delegate;

 

use strong references for their synthesized instance variables. To declare a weak reference, add an attribute to the property, like this:

@property (weak) id delegate;

 

Note: The opposite to weak is strong. There’s no need to specify the strong attribute explicitly, because it is the default.

 

 

 

Note: The opposite to __weak is __strong. Again, you don’t need to specify __strong explicitly, because it is the default.

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
IOS开发之——objective-c与javascript交互发布时间:2022-07-12
下一篇:
Objective-C——消息、Category和Protocol发布时间:2022-07-12
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap