hi there
am having a probelm resolving the challenge for if the word count is < 3
I can get it to work, but the error message is the same regardless if the word count is < 3 or the word isn't a real word.
so the approach I took was to write else if and else clauses, in the guard aspect of the code. however, swift doesnt like this approach. Was hoping someone could provide guidance on how i can incorporate an else if and an if with guard, so that swift differentiates between the word being less than 3 characters or more, and not a real word.
here is the code i wrote. apologies but the code is not formatting correctly to read, perhaps due to the coding errors.
'''
guard isReal(word: answer) else if word.count < 3 {
wordError(title: "Word not possible", message: "It is less than 3 characters")
else {
wordError(title: "Word not possible", message: "That isn't a real word")
return
}
}
// guard isReal(word: answer) else {
// wordError(title: "Word not possible", message: "That isn't a real word")
// return
// }
usedWords.insert(answer, at: 0)
newWord = ""
}
func isReal(word: String) -> Bool {
guard word.count >= 3 else {
return false
}
let checker = UITextChecker()
let range = NSRange(location: 0, length: word.utf16.count)
let misspelledRange = checker.rangeOfMisspelledWord(in: word, range: range, startingAt: 0, wrap: false, language: "en")
return misspelledRange.location == NSNotFound
}
'''