I am trying to get the last charcter from a given string. I know there is at least 1 character in the string. But when I write the code I get an error.
Here is my code:
func lastCharacter (of string: String) -> Character {
guard string != "" else {
return errorCharacter
}
return string[string.endIndex]
}
Here is the error:
error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).