Skip to content

Instantly share code, notes, and snippets.

@jingzhehu
Created October 26, 2018 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jingzhehu/fc22e28836f875da6960d8b3c1d193aa to your computer and use it in GitHub Desktop.
Save jingzhehu/fc22e28836f875da6960d8b3c1d193aa to your computer and use it in GitHub Desktop.
Split swift array into multiple 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)]) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment