自定义类实现NSCopying协议

@interface Fraction:NSObject<NSCopying>

-(id)copyWithZone:(NSZone*)zone

{

  Fraction *newFract = [[Fraction allocWithZone:zone]init];//如果Fraction类有子类,

  //应改为 id newFract = [[self class] allocWithZone:zone] init];//

  [newFract setTo:numerator over:denominator];

  return newFract;

}

你可能感兴趣的:(copy)