2011-05-05 33 views

回答

8

在聲明的屬性中沒有使用關鍵字原子。聲明的屬性默認情況下表現爲「原子」,因此您不必明確設置它。您只需通過添加非原子來更改默認行爲。由於這是一個編譯時指令,因此不需要在運行時更改此值,從而使「原子」不必要。

引述蘋果的The Objective-C Programming Language/Declared Properties

Atomicity

You can use this attribute to specify that accessor methods are not atomic. (There is no keyword to denote atomic.)

nonatomic Specifies that accessors are nonatomic. By default, accessors are atomic. Properties are atomic by default so that synthesized accessors provide robust access to properties in a multithreaded environment—that is, the value returned from the getter or set via the setter is always fully retrieved or set regardless of what other threads are executing concurrently. For more details, see 「Performance and Threading.」