I'd like to define a member in objective C class that can only be read outside the class (public getter). The writing (setter) however shell remain private.
I've read that It's possible to conceal object's setter using the readonly
property while exposing the getter using @synthesize
syntax but I'm not sure how it works exactly.
Base on this information here's what I did, and I wonder what's happening here under the hood, and if this is the proper way of doing so ?
@interface MyObject : NSObject
//This line suppose to conceal both getter and setter.
@property (readonly) MyCppBaseObject *myCppBaseObject;
- (void)setMyCppBaseObject:(NSString *)SomeInput;
@end
// This line suppose to tell the compiler that the getter is exposed
@synthesize myCppBaseObject = _myCppBaseObject;
@implementation MyObject
-(void)setMyCppBaseObject:(NSString *)SomeInput {
if (someCondition) {
self.myCppBaseObject = new myCppObjectDerive1(...);
} else {
self.myCppBaseObject = new myCppObjectDerive2(...);
}
}
@end
P.S. I've seen a different approach explained in the following link, but I wish to understand the above implementation.