iOS 深度拷贝

来源:互联网 发布:你难忘的事情 知乎 编辑:程序博客网 时间:2024/06/05 00:26



    <NSCopying>  .h文件中



-(instancetype)copyWithZone:(NSZone *)zone{

    PhoneAddressBooKModel *copied = [PhoneAddressBooKModelnew];

    copied.nodeId =self.nodeId;

    return copied;

}


调用

NSArray *copy = [[NSArrayalloc] initWithArray:listArrcopyItems:YES];


If YES, each object in array receives a copyWithZone:message to create a copy of the object—objects must conform to the NSCopying protocol. In a managed memory environment, this is instead of the retainmessage the object would otherwise receive. The object copy is then added to the returned array.

If NO, then in a managed memory environment each object in array simply receives a retain message when it is added to the returned array.


0 0