Skip to content

Instantly share code, notes, and snippets.

@hossamghareeb
Last active January 19, 2020 14:10
Show Gist options
  • Save hossamghareeb/b9089f9c0db907799899aa332bfa5db7 to your computer and use it in GitHub Desktop.
Save hossamghareeb/b9089f9c0db907799899aa332bfa5db7 to your computer and use it in GitHub Desktop.
ASCII value from one character String in Swift
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