-
Notifications
You must be signed in to change notification settings - Fork 60
Description
The author of a library controls the synthesis / implementation of an Objective-C property with the atomic
/nonatomic
attribute, see the docs on properties. Properties are atomic by default.
This means that something like @property NSString* name;
, by default, would be safe to read / modify concurrently (though not necessarily correct in the presence of other fields like lastname
, but that's a separate thing).
It is unclear whether we're allowed to rely on the attribute as consumers though? Because a lot of headers may use @property
(because it's the default), but in reality implement the property getter/setter as just a plain read/write of an instance variable. I.e. in reality be nonatomic
without declaring that.
As a data point, this StackOverflow answer says:
If you are writing your own setter/getters, atomic/nonatomic/retain/assign/copy are merely advisory.
Would be interesting to see if Swift uses the attribute anywhere? And maybe there are some frameworks where we can say it's safe to rely on the absence of the nonatomic
attribute to indicate an actually atomic property (probably Metal?), and others where we can't?