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