谁能用一个例子解释@property(nonatomic,retain)是什么意思?
我知道它是用来通知编译器自动生成 getter 和 setter, 但我想知道nonatomic,retain在这里起什么作用?如果有人用示例给出清晰的解释,那将会很有帮助
Possible Duplicate:
what is diff. b/w @property (nonatomic,assign) and @property (nonatomic,retain)
I know it is used to inform the compiler to generate the getters and the setters automatically,
But I want to know what role does nonatomic, retain play here ? It would be helpful if anyone gives a clear explanation with an EXAMPLE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非原子意味着当属性 getter 和 setter 通过 @synthesize 生成时,它们将不会使用任何锁定来实现。因此,当访问该值时,它可以随时更改,并且 getter 和 setter 不会阻塞;属性的多次读/写不会被序列化。
Retain 会将属性的保留计数加 1,以便在超出范围时不会释放。为了释放为该属性分配的内存,您可以在 dealloc 中释放它
nonatomic means that when the property getters and setters are generated via @synthesize, they will not be implemented using any locking. So, when accessing the value it can be changed at any time and the getters and setters do not block; multiple reads/writes of the property are not serialized.
Retain will increment the retain count of the property by 1 so that it will not release when it goes out of scope. In order to free the allocated memory for the property you would then release it in dealloc