プロトコル NSCopying に準拠したコピー方法を作成しようとしています。
私は次のクラスを持っています:
@interface Gene : NSObject <NSCopying>
{
int firstAllele;
int secondAllele;
}
メソッドで:
-(id) copyWithZone:(NSZone*) zone
{
id clonedGene = [[[self class] allocWithZone:zone] initWithAllele1:first andAllele2:second];
return clonedGene;
}
次の方法でメソッドを呼び出した場合:
Gene* gene1 = [[Gene alloc]initWithAllele1:4 andAllele2:2];
Gene* gene2 = [gene1 copy];
Gene1 の copy メソッドを呼び出しているときにクラッシュします。
メソッドを別の方法で呼び出す必要がありますか?
好きです[gene1 copyWithZone:(NSZone *)]
が、どのオブジェクトを渡す必要がありますか? NSZone オブジェクトを作成する必要がありますか? または、引数として渡すことができるデフォルトのものはありますか?
助けてくれてありがとう