Suppose I have a simple DTO class like this:
@interface MYNugget
@property (nonatomic, copy) NSString *color;
@end
@implementation MYNugget
// automatic @synthesize
@end
And I then later want to store this object in another class in a way such that it is not modifiable (that is, make the color property readonly via a - (void)freeze or something.
What is the best way to accomplish this short of writing my own setters?
The standard way is to have to classes, one mutable and an immutable one.
and
Your other class would just expose a
MYNuggetproperty, ideally again ascopy. That’s how we do it withNSStringall the time.