美文网首页
自定义对象的深拷贝/复制

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

作者: 然亦伞 | 来源:发表于2017-01-11 11:30 被阅读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;

    }

    相关文章

      网友评论

          本文标题:自定义对象的深拷贝/复制

          本文链接:https://www.haomeiwen.com/subject/mrxrbttx.html