数组分隔成两个一组

NSMutableArray *sourceM = [sourceArr mutableCopy];
    NSInteger count = sourceArr.count / 4; // 9个 三组 4 4 1
    
    NSMutableArray *temp = [NSMutableArray array];
    
    for (NSInteger i = 0; i < count; i++) {
        NSInteger from = 4*i - 1 > 0 ? 4*i - 1 : 0;
        NSArray *arr = [sourceM subarrayWithRange:NSMakeRange(from, 4)];
        [temp addObject:arr];
    }
    // 切出余数
    
    NSInteger leftCount = sourceArr.count - count * 4;
    if (leftCount > 0) {
        NSArray *leftArr = [sourceM subarrayWithRange:NSMakeRange(count * 4, leftCount)];
        [temp addObject:leftArr];
    }
    
    NSArray *resultArr = [temp copy];
原文地址:https://www.cnblogs.com/tufei7/p/10522098.html