Created
October 26, 2018 22:48
-
-
Save jingzhehu/fc22e28836f875da6960d8b3c1d193aa to your computer and use it in GitHub Desktop.
Split swift array into multiple chunks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment