Add @atomic, @nonatomic keywords to Objective-C
| Originator: | jonsterling | ||
| Number: | rdar://10685162 | Date Originated: | 12-Jan-2012 |
| Status: | Duplicate of 6130425 | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Feature Request | Reproducible: | Not Applicable |
Summary:
In iOS, the desired behavior for most properties is nonatomic; because atomic is the default for Objective-C, iOS projects end up littered with `nonatomic` annotations which clutters our interfaces with what are really implementation details. For compatibility reasons, the default atomicity for properties is unlikely to be changed.
I propose a new series of keywords to specify atomicity for multiple properties, after the manner of how @required and @optional specify requiredness for multiple methods in protocols. So, the current state of affairs leads to interfaces like the following:
@interface StrawManController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UILabel *descriptionLabel;
@property (strong, nonatomic) IBOutlet UIImageView *pictureView;
@property (strong, nonatomic) IBOutlet UIButton *explosionButton;
@property (weak, nonatomic) id <StrawManDelegate> delegate;
@property (weak, nonatomic) id <StrawManDataSource> dataSource;
@property (copy) NSString *someAtomicProperty;
@property BOOL anotherAtomicProperty;
@end
This interface could be simplified by the addition of keywords @nonatomic and @atomic. In the absense of any annotation to the contrary, atomic remains the default:
@interface StrawManController : UIViewController
@nonatomic
@property (strong) IBOutlet UILabel *titleLabel;
@property (strong) IBOutlet UILabel *descriptionLabel;
@property (strong) IBOutlet UIImageView *pictureView;
@property (strong) IBOutlet UIButton *explosionButton;
@property (weak) id <StrawManDelegate> delegate;
@property (weak) id <StrawManDataSource> dataSource;
@atomic
@property (copy) NSString *someAtomicProperty;
@property BOOL anotherAtomicProperty;
@end
The old property modifiers `atomic` and `nonatomic` should take precedence over the currently scoped default atomicity.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!