Why properties are always said to be made nonatomic in Objective C?

ios, objective-c

Solution

Declaring a property `atomic` makes compiler generate additional code that prevents concurrent access to the property. This additional code locks a semaphore, then gets or sets the property, and then unlock the semaphore. Compared to setting or getting a primitive value or a pointer, locking and unlocking a semaphore is expensive (although it is usually negligible if you consider the overall flow of your app).

Since most of your classes under iOS, especially the ones related to UI, will be used in a single-threaded environment, it is safe to drop `atomic` (i.e. write `nonatomic`, because properties are `atomic` by default): even though the operation is relatively inexpensive, you do not want to pay for things that you do not need.

Problem

It is said that `nonatomic` option will make your setter method run faster. I googled it but am not able to understand. Could someone tell me why?

Original source

Related problems