开发者

Why should I ever use nonatomic in a property? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Objective-C properties: atomic vs nonatomic

By default all properties in Objective-C are atomic. If I need nonatomic I have to declare it. But I wonder why should I ever use nonatomic? Even if my applications are not multi thre开发者_如何学运维aded, atomic seems like the way to do it. What are the advantages of nonatomic?


A short answer is performance. If you declare properties as atomic, the synthesized accessors will use locks to ensure that values are fully retrieved and set. If you don't need this, e.g., your application is single-threaded, you're incurring a performance penalty for those locks without getting a benefit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜