Objective c 中这些@properties 有什么区别?

发布于 2024-12-21 11:20:38 字数 410 浏览 5 评论 0原文

atomicnonatomic 属性之间有什么区别,它与保留它有什么关系?

我知道@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咋地 2024-12-28 11:20:38

retainatomic/nonatomic 是正交的,这意味着它们的任何组合都是有效的。 retain 表示该对象与其保留的属性之间存在很强的联系(即,当该对象指向该属性时,不应释放该属性引用的对象)。 atomic/nonatomic 表示对属性的访问应该或不应该同步。这是对原子/非原子的精彩解释

请注意,只有当您使用 @synthesize 时,所有这些才有意义。

retain and atomic/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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文