dimanche 29 mars 2015

Swift hasSuffix method crashing app

I'm trying to detect whether or not a user's input ends with a blank space, and if it does, to remove that space. I'm using the .hasSuffix() method to see if the space exists, and it should return a boolean variable that I can test for and determine the proper course of action. However, when I check whether the value is true or false, the app crashes. Any thoughts on why that might be? Here's the code:



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)

Aucun commentaire:

Enregistrer un commentaire