Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ascii
extension String {
var ascii: Int {
return Int(unicodeScalars.first!.value)
}
}
extension Int {
var toString: String {
return String(UnicodeScalar(self)!)
}
}
var alphabet: [String] = []
for i in "A".ascii..."Z".ascii {
alphabet.append(i.toString)
}
print("A".ascii) // 65
print("z".ascii) // 122
print(66.toString) // B
print(121.toString) // y
print(alphabet)
// ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment