Created
November 3, 2022 20:06
-
-
Save gchumillas/6ca438974caa4f3e49b8e869bdac8aba to your computer and use it in GitHub Desktop.
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 String { | |
func chunks(_ size: Int) -> [String] { | |
stride(from: 0, to: self.count, by: size).map { | |
let i0 = self.index(self.startIndex, offsetBy: $0) | |
let i1 = self.index(self.startIndex, offsetBy: min($0 + size, self.count)) | |
return "\(self[i0..<i1])" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment