の実装について頭の中でいくつかのことを整理しようとしてcopyWithZone:
います。次のことについて誰でもコメントできますか...
// 001: Crime is a subclass of NSObject.
- (id)copyWithZone:(NSZone *)zone {
Crime *newCrime = [[[self class] allocWithZone:zone] init];
if(newCrime) {
[newCrime setMonth:[self month]];
[newCrime setCategory:[self category]];
[newCrime setCoordinate:[self coordinate]];
[newCrime setLocationName:[self locationName]];
[newCrime setTitle:[self title]];
[newCrime setSubtitle:[self subtitle]];
}
return newCrime;
}
// 002: Crime is not a subclass of NSObject.
- (id)copyWithZone:(NSZone *)zone {
Crime *newCrime = [super copyWithZone:zone];
[newCrime setMonth:[self month]];
[newCrime setCategory:[self category]];
[newCrime setCoordinate:[self coordinate]];
[newCrime setLocationName:[self locationName]];
[newCrime setTitle:[self title]];
[newCrime setSubtitle:[self subtitle]];
return newCrime;
}
001:
クラス名を直接書くのが最善ですか、それとも
[[Crime allocWithZone:zone] init]
使用する必要があります[[[self Class] allocWithZone:zone] init]
か?iVar のコピーに使用
[self month]
しても問題ありませんか、それとも iVar に直接アクセスする必要があり_month
ますか?