我在代码中的“==”处收到错误 无法使用类型为'(@lvalue String,@lvalue Character)'的参数列表调用'=='
--------代表我的代码
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")
}
}
答案 0 :(得分:2)
一种非常简单的方法是使用string interpolation:
if guessLetter == "\(oneLetter)"
另一个是让guessLetter成为一个角色:
var guessLetter: Character = "g"