使用未解析的标识符 - Swift 项目 2 的应用程序开发
Use of unresolved identifier - app development with Swift Project 2
抱歉 - 我知道这是一个完整的初学者问题,但我已经用 google 搜索了半天,仍然无法自己解决这个问题。
我正在使用 xCode 8.3 并尝试完成 apple - app development with swift course - end of unit project 2. 我被告知(Apple book)我应该能够 运行 应用程序没有构建失败,即使它没有完成。
当我将以下代码添加到我的 ViewControler 文件时,在 class ViewController: UIViewController.
中出现未解决的标识符错误
func updateUI() {
correctWordLabel.text = game.formattedWord
scoreLabel.text = "Wins: \(totalWins), Losses: \(totalLosses)"
treeImageView.image = UIImage(named: "Tree \(currentGame.incorrectMovesRemaining)")
}
xCode 建议我将其更改为 Game.formattedWord,但是当我收到“实例成员 'formattedWord' 不能用于类型 'Game' ViewController.Swift”时.
有人可以帮忙吗?
我已经检查了 Apple 的示例代码大约 100 次,他们明确表示代码中应该是 game.formattedWord。
谢谢!
尝试correctWordLabel.text = currentGame.formattedWord
我认为这是一个错字。
在您的代码的前面,您创建了一个名为 currentGame
的 Game 结构实例,因此您正在访问该实例中的 formattedWord 变量。这就是为什么您无法将其更改为游戏的原因。游戏就像结构的蓝图。 currentGame 是你真正的“东西”希望有一定道理。
抱歉 - 我知道这是一个完整的初学者问题,但我已经用 google 搜索了半天,仍然无法自己解决这个问题。
我正在使用 xCode 8.3 并尝试完成 apple - app development with swift course - end of unit project 2. 我被告知(Apple book)我应该能够 运行 应用程序没有构建失败,即使它没有完成。
当我将以下代码添加到我的 ViewControler 文件时,在 class ViewController: UIViewController.
中出现未解决的标识符错误func updateUI() {
correctWordLabel.text = game.formattedWord
scoreLabel.text = "Wins: \(totalWins), Losses: \(totalLosses)"
treeImageView.image = UIImage(named: "Tree \(currentGame.incorrectMovesRemaining)")
}
xCode 建议我将其更改为 Game.formattedWord,但是当我收到“实例成员 'formattedWord' 不能用于类型 'Game' ViewController.Swift”时.
有人可以帮忙吗?
我已经检查了 Apple 的示例代码大约 100 次,他们明确表示代码中应该是 game.formattedWord。
谢谢!
尝试correctWordLabel.text = currentGame.formattedWord
我认为这是一个错字。
在您的代码的前面,您创建了一个名为 currentGame
的 Game 结构实例,因此您正在访问该实例中的 formattedWord 变量。这就是为什么您无法将其更改为游戏的原因。游戏就像结构的蓝图。 currentGame 是你真正的“东西”希望有一定道理。