0
我在我的代碼中發現一個黃色錯誤,我不確定爲什麼我要得到它。這裏是我的代碼:Xcode錯誤「表達式結果未使用」
for (int lives = 5; lives > 0; lives--)
{
self.HangmanStatus.text = @"Lives Left: %d", lives; //<-- Getting error here
}
任何幫助將非常感謝, 謝謝!
我在我的代碼中發現一個黃色錯誤,我不確定爲什麼我要得到它。這裏是我的代碼:Xcode錯誤「表達式結果未使用」
for (int lives = 5; lives > 0; lives--)
{
self.HangmanStatus.text = @"Lives Left: %d", lives; //<-- Getting error here
}
任何幫助將非常感謝, 謝謝!
正確的語法是:
self.HangmanStatus.text = [NSString stringWithFormat: @"Lives Left: %d", lives];
這是您第一次創建NSString嗎?您沒有使用any of the NSString methods used to create one.
你遇到的具體錯誤是什麼? – Chris
令人困惑的錯誤消息的原因是在(Objective)C中,例子中的逗號('...%d「,lives')實際上是*逗號運算符*的用法 - 它很少使用 - 而不是使用逗號作爲分隔符(@JohnSauer已經指出你如何修正你的代碼。) – CRD