Why should I ever use nonatomic in a property? [duplicate]
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.
精彩评论