objective-c ARC readonly properties and private setter implementation objective-c ARC readonly properties and private setter implementation ios ios

objective-c ARC readonly properties and private setter implementation


Yes, that is adequate, but you don't even need that much.

You can do

- (void)setMyProperty:(NSString *)newValue{       myProperty = newValue;}

The compiler will do the right thing here.

The other thing though, is you don't even need THAT. In your class extension you can actually respecify @property declarations.

@interface SomeClass : NSObject@property (nonatomic, readonly, strong) NSString *myProperty;@end@interface SomeClass()@property (nonatomic, readwrite, strong) NSString *myProperty;@end

Doing that, you just need to synthesize and you have a private setter that is synthesized for you.


You can redeclare your property as readwrite in interface extension:

@interface SomeClass()@property (nonatomic, strong, readwrite) NSString *myProperty;@end