Skip to content

Instantly share code, notes, and snippets.

@trilliwon
Created September 23, 2018 04:59
Show Gist options
  • Save trilliwon/b8d41d8c7fc19261af0a430989643f4d to your computer and use it in GitHub Desktop.
Save trilliwon/b8d41d8c7fc19261af0a430989643f4d to your computer and use it in GitHub Desktop.
Swift string subscript using Int value as index
extension String {
subscript(i: Int) -> Character? {
guard i < self.count else {
return nil
}
return self[self.index(self.startIndex, offsetBy: i)]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment