I want to test if the input string is "". If the input string is "", then return false.
var x = ""
func beginsWithVowel(x: String) -> Bool {
if x.characters[x.startIndex] == "a" || x.characters[x.startIndex] == "A"{
return true
}else if x.characters[x.startIndex] == "e" || x.characters[x.startIndex] == "E"{
return true
}else if x.characters[x.startIndex] == "i" || x.characters[x.startIndex] == "I"{
return true
}else if x.characters[x.startIndex] == "o" || x.characters[x.startIndex] == "O"{
return true
}else if x.characters[x.startIndex] == "u" || x.characters[x.startIndex] == "U"{
return true
}else {
return false
}
}
beginsWithVowel(x: x)
But I got a error: fatal error: Can't form a Character from an empty String. How can i fix it? Thank You. P.S. cant use optional string and the problem wan't how to check empty string, but why it cant return bool in function.