Your base method copyWithZone:should look like this:
-(id)copyWithZone:(NSZone *)zone {
BaseClass *base = [[[self class] allocWithZone:zone] init];
return base;
}
Your derived methods copyWithZone:should look like this:
-(id)copyWithZone:(NSZone *)zone {
DerivedClass *derived = [super copyWithZone:zone];
return derived;
}
Also make sure you make deep copies of strong links and shallow copies of weak links. Thus, for example, to copy members of type NSStringand NSArray(each of them with strongly referenced elements and one with weak):
derived.strongString = [[strongString copyWithZone:zone] autorelease];
derived.weakString = weakString;
derived.strArrWStrVals = [[strArrWStrVals copyWithZone:zone] autorelease];
derived.strArrWWeakVals = [[[NSArray allocWithZone:zone]
initWithArray:strArrWWeakVals] autorelease];
derived.weakArray = weakArray;
(Usually weak members are also assigned / saved, and strong variables are copied.)
, - initWithMyself: .