Last active
January 19, 2020 14:10
-
-
Save hossamghareeb/b9089f9c0db907799899aa332bfa5db7 to your computer and use it in GitHub Desktop.
ASCII value from one character String in Swift
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 { | |
var ascii: Int { | |
guard let u = UnicodeScalar(self) else { return -1 } | |
return Int(u.value) | |
} | |
} | |
"a".ascii // 97 | |
"A".ascii // 65 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment