ios数组

//枚举遍历和for循环遍历可以在遍历的同时删除里面的元素,但用for in会出现数组越界异常,要想用for in可以逆序遍历,这样就不会有问题,

嵌套数组,获取所有section里面所有cell,根据cell相同字段值排序:


- (void)covertData{

    _filterArray = [[NSMutableArray alloc]init];

    NSString *property = @"matchName";

    __block  NSString *value;



    //遍历外层,获取各个section

    [self.headerModelArrays enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

        ExpandListHeaderModel *headerModel = obj;

        //遍历内层,获取各个cell

        [headerModel.data enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

            ExpandListCellModel *cellModel = obj;



            value = cellModel.match_name;

            NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K CONTAINS %@", property, value];

            NSArray *filterCommonArray = [_filterArray filteredArrayUsingPredicate:pred];

            if (filterCommonArray.count == 0) {

                //预测到无这个字段值,便放入

                FilterItemModel *filterModel = [[FilterItemModel alloc]init];

                filterModel.matchName = cellModel.match_name;

                filterModel.matchCount = 1;//初始化1

                [_filterArray addObject:filterModel];



            }else{

                //预测到有这个值,就取出这个值并加1

                FilterItemModel *filterModel = filterCommonArray[0];

                filterModel.matchCount += 1;

            }

        }];

    }];

    NSLog(@"%@",_filterArray);

    _filterArrays = [ABCGroup groupFromArray:_filterArray];

    NSLog(@"%@",_filterArrays);

}

你可能感兴趣的:(ios数组)