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

数组对象深拷贝

作者: 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];
    
    

    相关文章

      网友评论

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

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