我试图检测用户的输入是否以空格结尾,如果是,则删除该空格。我使用.hasSuffix()方法来查看空间是否存在,它应该返回一个我可以测试的布尔变量并确定正确的操作过程。但是,当我检查值是true还是false时,应用程序崩溃。对于为什么会这样的想法?这是代码:
var userGuess = userGuessField.text.lowercaseString
var guessEndsWithSpace: Bool = userGuess.hasSuffix(" ")
// The above will return true if the string ends with a space, so when this happens, remove the space and then check their guess
if (guessEndsWithSpace == true) {
println("Guess ends with a space")
// checkAnswer(userGuess)
} else {
println("Guess does not end with a space")
// Otherwise, just check their guess
// checkAnswer(userGuess)