Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

swift split an array into chunks

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 by www.hackingwithswift.com #
 
PREVIOUS NEXT
Tagged: #swift #split #array #chunks
ADD COMMENT
Topic
Name
3+6 =