I have an object that holds a dictionary JSONData
. From the header file, and to the other classes that\'ll access it, I want this property to only be read-only
You need a separate private mutable variable in your implementation. You can override the getter to return an immutable object.
@interface MyObject () {
NSMutableDictionary *_mutableJSONData;
}
@end
@implementation MyObject
// ...
-(NSDictionary *)JSONData {
return [NSDictionary dictionaryWithDictionary:_mutableJSONData];
}
// ...
@end
No need to implement the setter, as it is readonly
.