My classes implement NSCopying like this:
@implementation MyClass
- (id) copyWithZone: (NSZone *) zone {
MyClass *copy = [[MyClass allocWithZone: zone] init];
// Copy instance variables
return copy;
}
@end
That means the copy is allocated in the required memory zone. In case the object contains instance variables that need to be copied, too, e.g. mutable arrays, should I use their copyWithZone: message and pass the zone along, instead of just calling copy?
Additionally, if there are instance variables that I want to instantiate directly instead of copying an object, will I have to allocate those by using the allocWithZone: class method?
Zone is obsolete – there’s nothing special to do with it. If you copy your ivars also, you can safely ignore it and just call copy on them.