Swift 2 以 NSException 类型的未捕获异常终止
Swift 2 terminating with uncaught exception of type NSException
我收到一个 NSException 错误,自从使用更新的 swift 后我无法理解该错误 2. 我知道该异常很常见并且本身并没有真正帮助。我已经包含了我正在使用的代码。该代码是从一个计算器应用程序开始的。虽然此代码在 swift 中运行得非常好,但它现在在更新后的 swift 2 中提供了异常。
class ViewController: UIViewController {
@IBOutlet weak var mainDisplay: UILabel!
@IBAction func appendDigit(sender: UIButton) {
let digit = sender.currentTitle
print("digit = \(digit)")
}}
据我所知,错误与 print("digit = \(digit)")
行有关。在 swift 2 中,println 被删除并合并到 print 中,但我不确定为什么调用 digit 会导致异常?我是 swift 的新手,所以如果能帮助我理解这个问题,我将不胜感激。
谢谢
您的问题与appendDigit:
方法无关。您应该检查 Storyboard 或 XIB,因为您的 IBOutlet
存在连接问题,这可能是在您将变量从 maindisplay
重命名为 mainDisplay
.
之后出现的
添加:
解决方案是在链接 UILabel
处查看 Storyboard 或 XIB,移除出口连接,然后使用新重命名的 mainDisplay IBOutlet var
重新设置。
我收到一个 NSException 错误,自从使用更新的 swift 后我无法理解该错误 2. 我知道该异常很常见并且本身并没有真正帮助。我已经包含了我正在使用的代码。该代码是从一个计算器应用程序开始的。虽然此代码在 swift 中运行得非常好,但它现在在更新后的 swift 2 中提供了异常。
class ViewController: UIViewController {
@IBOutlet weak var mainDisplay: UILabel!
@IBAction func appendDigit(sender: UIButton) {
let digit = sender.currentTitle
print("digit = \(digit)")
}}
据我所知,错误与 print("digit = \(digit)")
行有关。在 swift 2 中,println 被删除并合并到 print 中,但我不确定为什么调用 digit 会导致异常?我是 swift 的新手,所以如果能帮助我理解这个问题,我将不胜感激。
谢谢
您的问题与appendDigit:
方法无关。您应该检查 Storyboard 或 XIB,因为您的 IBOutlet
存在连接问题,这可能是在您将变量从 maindisplay
重命名为 mainDisplay
.
添加:
解决方案是在链接 UILabel
处查看 Storyboard 或 XIB,移除出口连接,然后使用新重命名的 mainDisplay IBOutlet var
重新设置。