What is an easy way to break an NSArray with 4000+ objects in it into multiple arrays with 30 objects each?

前端 未结 3 1121
终归单人心
终归单人心 2020-11-30 06:37

What is an easy way to break an NSArray with 4000 objects in it into multiple arrays with 30 objects each?

So right now I have an NSArray *stuff where [stuff count]

3条回答
  •  情书的邮戳
    2020-11-30 07:20

    Converted the answer of @samvermette to SWIFT 3

            var arrayOfArraySlices = [ArraySlice]() // array of array slices
    
            var itemsRemaining = orderArray.count
            var j = 0
    
            while itemsRemaining > 0 {
                let range = NSRange(location: j, length: min(20, itemsRemaining));
                let arraySlice = orderArray[range.location..

提交回复
热议问题