ios数组

作者: 微小的沙土 | 来源:发表于2018-08-27 11:03 被阅读0次

    //枚举遍历和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数组

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