数组对象深拷贝

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

你可能感兴趣的:(数组对象深拷贝)