阅读背景:

NSobject的复制以及其他一些类方法和实例方法的理解

来源:互联网 
copy和copyWithZone

@interface Animal :NSObject <NSCopying>  //在后面包含NSCOPYING协议 
在M文件中复制ANimal类中的对象.
- (id)copyWithZone:(NSZone *)zone                        //copy使用方法需要运行- (id)copyWithZone:(NSZone *)zone实例方法  
{
   Animal * animal =[[Animal allocWithZone]init];     //allocwithzone=alloc.意思一样 
   animal.weight=_weight;                                      //如果不让weight=_weight,则当愿animal.weight设值,复制的对象中
   return animal;                                                    //weight将无法获得
} 
copy和copyWithZone

@interface Animal :NSObj



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: