I’d like to declare a public immutable property:
@interface Foo
@property(strong, readonly) NSSet *items;
@end
…backed with a mutable type in the implementation file:
@interface Foo (/* private interface*/)
@property(strong) NSMutableSet *items;
@end
@implementation
@synthesize items;
@end
What I want is a mutable collection in the implementation that gets cast into an immutable one when accessed from the outside. (I don’t care that the caller can cast the instance back to NSMutableSet
and break the encapsulation. I live in a quiet, decent town where such things don’t happen.)
Right now my compiler treats the property as NSSet
inside the implementation. I know there are many ways to get it working, for example with custom getters, but is there a way to do it simply with declared properties?