Question : swift split an array into chunks
Answered by : rens-wijnmalen
extension Array { func chunked(into size: Int) -> [[Element]] { return stride(from: 0, to: count, by: size).map { Array(self[$0 ..< Swift.min($0 + size, count)]) } }
}
let numbers = Array(1...100)
let result = numbers.chunked(into: 5)
Source : https://www.hackingwithswift.com/example-code/language/how-to-split-an-array-into-chunks | Last Update : Tue, 15 Feb 22