遍历删除,顺序删除可能删除的不彻底,有遗留.错误的删除方法:
NSMutableArray <HPLonelyShopHomepageModel *>*temp = [typeListArray mutableCopy]; [temp enumerateObjectsUsingBlock:^(HPLonelyShopHomepageModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (!obj.userList.count) { [temp removeObject:obj]; } }];
逆序删除即可:
NSMutableArray <HPLonelyShopHomepageModel *>*temp = [typeListArray mutableCopy]; HPLog(@"之前:%td",temp.count); [temp enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(HPLonelyShopHomepageModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (obj.userList.count == 0) { [temp removeObject:obj]; HP_DEBUG_Log(@"走了删除方法"); } }];