數(shù)組對象深拷貝

aaa.jpg
  • 1.首先自定義對象需要遵循 NSCopying, NSMutableCopying 協(xié)議 嵌套類型的子對象也需要遵循

    1. 實現(xiàn) copyWithZone:(nullable NSZone *)zone mutableCopyWithZone:(NSZone *)zone
    1. 調(diào)用[NSArray alloc] initWithArray:self.dataArr copyItems:YES] 返回一個copy 的數(shù)組
- (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];

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容