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

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

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

@interface CustomerListCellInfoObject : NSObject

//自定义对象的深拷贝

-(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;

}

你可能感兴趣的:(自定义对象的深拷贝/复制)