Reputation: 41470
In Objective-C, under what scenarios/use case do you declare atomicity for your properties in your iOS/cocoa development? Please list practical use cases.
Note: I understand the difference between atomic and non-atomic, but there have been few who have answered this in the context of: "I have used atomic property when I am doing this and it's absolutely needed". Most answers on atomic/non-atomic have been theoretical and superficial.
Upvotes: 4
Views: 298
Reputation: 8546
By default @property makes your property atomic. you specify nonatomic when you don't want it. Atomicity is useful when you have two object that might modify the same object at the same moment.
Upvotes: 3
Reputation: 3612
Put in a simple way:
If there are a risk that two threads can get/set the same property at the same time, then you need to use atomic
. The atomic
keyword prohibits a property to be changed when another thread is getting it.
The default value atomic
is slower then nonatomic
. That's why you most often use nonatomic
Upvotes: 1