As I assumed, this should work’s fine for immutable object under ARC:
- (id) copyWithZone:(NSZone *)zone {
return self;
}
But if I need deep copy, I should write something like this:
- (id) copyWithZone:(NSZone *)zone {
Immutable *copy = [[Immutable alloc] initWithStr:str];
return copy;
}
So, If I assumed right, ARC would understand situation (1) and (2) and make right decision about “+1” for references.
Am I right ?
Seems I’m right: I can’t find any concrete documentation on topic, but I create separate test project with ARC turned off, then choose migrate to ARC. Here is code without ARC:
This is what I got after migration:
It’s a magic how ARC works sometimes, but seems we should just believe it will doing it’s job well. 🙂