自定义对象的深拷贝/复制

2017-01-11  本文已影响26人  然亦伞

注意从数组中拿数据传输,地址传递造成的原数据污染!

自定义对象的深拷贝要实现NSCoping方法。

@interface CustomerListCellInfoObject : NSObject <NSCopying>

//自定义对象的深拷贝

-(id)copyWithZone:(NSZone *)zone

{

CustomerListCellInfoObject *customer = [[[self class] allocWithZone:zone]init];

customer.cname = self.cname;

customer.ctel1 = self.ctel1;

customer.ctel2 = self.ctel2;

customer.attitude = self.attitude;

customer.icon = self.icon;

customer.lid = self.lid;

customer.cnameFirstChat = self.cnameFirstChat;

return customer;

}

上一篇下一篇

猜你喜欢

热点阅读