Reputation: 19
I am getting the error at the "==" in code Cannot invoke '==' with an argument list of type '(@lvalue String, @lvalue Character)'
--------representation of my code
var randomWord = "horse"
var guessLetter = "g"
for var charIndex = 0; charIndex < countElements(randomWord); charIndex++ {
var index = advance(str.startIndex, charIndex)
var oneLetter = str[index]
if guessLetter == oneLetter {
println("ok")
} else {
println("nope")
}
}
Upvotes: 0
Views: 279
Reputation: 5119
One very simple way is to use string interpolation:
if guessLetter == "\(oneLetter)"
Another is to have guessLetter be a Character:
var guessLetter: Character = "g"
Upvotes: 2