美文网首页
数组对象深拷贝

数组对象深拷贝

作者: iOSTbag | 来源:发表于2019-11-05 11:11 被阅读0次
aaa.jpg
  • 1.首先自定义对象需要遵循 NSCopying, NSMutableCopying 协议 嵌套类型的子对象也需要遵循

    1. 实现 copyWithZone:(nullable NSZone *)zone mutableCopyWithZone:(NSZone *)zone
    1. 调用[NSArray alloc] initWithArray:self.dataArr copyItems:YES] 返回一个copy 的数组
- (id)copyWithZone:(nullable NSZone *)zone {
    GSKFleetManagementModel *model = [[GSKFleetManagementModel allocWithZone:zone]init];
    model.status = _status;
    model.statusArray = [self.statusArray copy];
    model.index = self.index;
    model.isId = [self.isId copy];
    model.current_status = [self.current_status copy];
    model.department = [self.department copy];
    model.location = [self.location copy];
    model.vehicle_make = [self.vehicle_make copy];
    model.vehicle_number = [self.vehicle_number copy];
    model.current_mileage = [self.current_mileage copy];
    model.workshop = [self.workshop copy];
    model.note = [self.note copy];
    model.score = [self.score copy];
    model.submited_at = [self.submited_at copy];
    model.reject_rich_info = [self.reject_rich_info copy];
    model.target_step = [self.target_step copy];

    return model;
}

- (id)mutableCopyWithZone:(NSZone *)zone {
    GSKFleetManagementModel *model = [[GSKFleetManagementModel allocWithZone:zone]init];
    model.status = _status;
    model.statusArray = [self.statusArray copy];
    model.index = self.index;
    model.isId = [self.isId copy];
    model.current_status = [self.current_status copy];
    model.department = [self.department copy];
    model.location = [self.location copy];
    model.vehicle_make = [self.vehicle_make copy];
    model.vehicle_number = [self.vehicle_number copy];
    model.current_mileage = [self.current_mileage copy];
    model.workshop = [self.workshop copy];
    model.note = [self.note copy];
    model.score = [self.score copy];
    model.submited_at = [self.submited_at copy];
    model.reject_rich_info = [self.reject_rich_info copy];
    model.target_step = [self.target_step copy];
    return model;
}

- (id)copyWithZone:(NSZone *)zone{
    GSKFeelManaRejectModel *model = [[GSKFeelManaRejectModel allocWithZone:zone] init];
    model.isSeleted = self.isSeleted;
    model.title = [self.title copy];
    model.reason = [self.reason copy];
    model.mudid = [self.mudid copy];
    model.at = [self.at copy];
    model.height = self.height;
    return model;
}

- (id)mutableCopyWithZone:(NSZone *)zone{
    GSKFeelManaRejectModel *model = [[GSKFeelManaRejectModel allocWithZone:zone] init];
    model.isSeleted = self.isSeleted;
    model.title = [self.title copy];
    model.reason = [self.reason copy];
    model.mudid = [self.mudid copy];
    model.at = [self.at copy];
    model.height = self.height;
    return model;

}

    NSArray *copyArr = [[NSArray alloc] initWithArray:self.dataArr copyItems:YES];
    self.model = copyArr[indexPath.row];

相关文章

  • Javascript深拷贝

    什么是深拷贝 创建一个新的对象或数组时,将原对象/数组的“值”拷贝,而不是“引用”。 深拷贝 数组拷贝不存在多层嵌...

  • 2018-05-22

    数组与对象的深拷贝

  • C++封装(二)

    第2章 对象成员与对象数组 第3章 深拷贝与浅拷贝 浅拷贝: 深拷贝: 第4章 对象指针 对象指针: 栈中: 对象...

  • OC 数组mutableCopy能不能把数组里边的对象深拷贝?

    一. 数组深拷贝,数组中对象不实现NSCopying协议 Person类 使用 结果: 从结果来看虽然数组是深拷贝...

  • 浅拷贝与深拷贝

    /*浅拷贝:拷贝地址*/ /*深拷贝:拷贝对象*/ 用Strong修饰不可变数组:浅拷贝 用Copy修饰不可变数组...

  • js深拷贝和浅拷贝区别

    浅拷贝和深拷贝的区别 1.浅拷贝:将源对象或者原数组的引用 ```直接赋给``` 新对象/新数组 ,新对象/新...

  • 深浅拷贝

    浅拷贝将原对象/原数组的引用直接赋值给新对象/新数组,新对象/新数组只是原对象/原数组的一个引用。 深拷贝将原对象...

  • 深拷贝和浅拷贝

    1. 深拷贝和浅拷贝 1.浅拷贝: 将原对象或原数组的引用直接赋给新对象,新数组,新对象/数组只是原对象的一个引用...

  • 关于OC中数组的深、浅拷贝的小总结

    简而言之:数组的深拷贝,仅仅只是拷贝数组的内容,数组内元素的地址不会变,如果想要数组内的对象元素也深拷贝,则数组内...

  • 数组对象深拷贝

网友评论

      本文标题:数组对象深拷贝

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