我尝试创建一个复制方法,该协议符合协议NSCopying。copyWithZone:(深层复制)崩溃的子类
我有以下类:
@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];
同时调用拷贝崩溃基因的方法1。
我必须以不同的方式调用方法吗?
像[gene1 copyWithZone:(NSZone *)]
但是我需要传递什么对象?我必须创建一个NSZone对象吗?还是有一个默认的我可以作为参数传递?
感谢您的帮助
崩溃后的调试器输出是什么? – hoha 2011-03-26 11:22:22
好吧我想通了,我不得不添加一个副本,而不是只传递第一个和第二个等位基因对象: – Aranir 2011-04-05 00:09:11