I'm trying to figure out how to obtain the numeric value of characters that are contained in a String object.
e.g.
let checkString = "ball"
for i in checkString.characters {
var val = Int(String(i))!
print(val)
}
I would like my output to be:
ASCII value of 'b'
ASCII value of 'a'
ASCII value of 'l'
ASCII value of 'l'
However, I get instead the error:
fatal error: unexpectedly found nil while unwrapping an Optional value
In Java, the equivalent code is:
int val = str.charAt(i)
Can anyone see where it is I'm going wrong?