2011-05-05 49 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.”