A friend told me that the @property default for scalar properties (BOOL, NSInteger, etc.) is nonatomic. I.e.,
@property BOOL followVenmo;
defaults to
@property (nonatomic) BOOL followVenmo;
But, I was always under the impression that the default is always atomic, scalar or not.
Which is it?
Based on my research of a couple other related questions:
I shall abide by @Rhubarb's recommendation:
From the Developer Documentation
Atomic properties ensures that you will get or set a whole value. For example, setting a CGRect from 2 threads will end up with one or the other, not some combination of the two.
For retained properties, it also ensures that the result can outlive the receiver. For example, you get a result from an object that is released by another thread before the call finishes, but the result is retained and autoreleased on your behalf so it is still valid.
Be careful with this "scalar" terminology. An NSString * property is also a pointer, exactly like the example you provided with a pointer to BOOL.
From Apple docs: (The Objective-C Programming Language)
You can't apply an object-level lock in something that's not an object, so (non)atomic in properties of primitive types has basically no effect.
You can conclude that atomic only applies to object properties, and this is reinforced in the docs:
To clarify whether you should specify one or the other: technically, properties without a
nonatomic
are considered atomic, but remember that it has no meaning for primitive types. Thus, you may want to save some typing and avoidnonatomic
in these.