Why do we have to put exclamation point when I create, in this case, a range?
Example:
var str = "joe satriani"
var range = str.startIndex..<str.characters.index(of: " ")!
If I don't put it I get an error.
Why do we have to put exclamation point when I create, in this case, a range?
Example:
var str = "joe satriani"
var range = str.startIndex..<str.characters.index(of: " ")!
If I don't put it I get an error.
There might not be an index of " "
if there is no space in the string, therefore returning nil
.
var str = "stringwithnospaces"
var range = str.startIndex..<str.characters.index(of: " ") // nil