I’m writing framework and want to expose certain internal property as readonly.
So I added a readonly property in the header and
synthesize it manually like this.
-(NSMutableURLRequest*) readonlyRequest {
return [self.request copy];
}
The caller gets a copy which can still be mutated, but doesn’t affect the internal property.
Is this the right way to do? Or are there some other better alternatives?
The code is compiled for ARC, so no autorelease
That’s actually incorrect. The caller will get an
NSURLRequest*. You need to use-mutableCopyinstead.Alternatively, you should declare this as just
NSURLRequest *(which is probably better, unless you have some reason to think the caller needs a mutable request).Edit: Removed the bit about
autoreleasebecause the question was updated to indicate this is ARC.