Objective c 中这些@properties 有什么区别?
atomic
和 nonatomic
属性之间有什么区别,它与保留它有什么关系?
我知道@property(retain)是什么,在这个网站中定义:@property是一个目标-声明属性的 C 指令。括号中的“retain”指定 setter 应保留输入值,该行的其余部分仅指定属性的类型和名称。
所以 @property(retain) 会执行上面所述的操作,但是非原子/原子如何与保留属性一起发挥作用呢?
@property(nonatomic, retain)
@property(atomic, retain)
What is the difference between atomic
and nonatomic
properties, and what does it have to do with retaining it?
I know what @property(retain) is, defined in this website: The @property is an Objective-C directive which declares the property. The "retain" in the parenthesis specifies that the setter should retain the input value, and the rest of the line simply specifies the type and the name of the property.
So @property(retain)
does what was stated above, but how does nonatomic/atomic function with the retain property?
@property(nonatomic, retain)
@property(atomic, retain)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
retain
和atomic
/nonatomic
是正交的,这意味着它们的任何组合都是有效的。retain
表示该对象与其保留的属性之间存在很强的联系(即,当该对象指向该属性时,不应释放该属性引用的对象)。atomic
/nonatomic
表示对属性的访问应该或不应该同步。这是对原子/非原子的精彩解释。请注意,只有当您使用
@synthesize
时,所有这些才有意义。retain
andatomic
/nonatomic
are orthogonal, meaning that any combination of them is valid.retain
says that there is a strong link between the object and its retained property (i.e. the object referenced by the property should not be released while it is pointed to by this object).atomic
/nonatomic
means that the access to the property should or should not be synchronized. Here is a great explanation of the atomic/nonatomic.Note that all of this is meaningful only when you use
@synthesize
.