Created
September 23, 2018 04:59
-
-
Save trilliwon/b8d41d8c7fc19261af0a430989643f4d to your computer and use it in GitHub Desktop.
Swift string subscript using Int value as index
This file contains hidden or 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 { | |
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