Swift 'WKInterfaceLabel' 没有名为 'text' 的成员

Swift 'WKInterfaceLabel' does not have a member named 'text'

我正在开发 iWatch 应用程序,但遇到以下错误:

'WKInterfaceLabel' does not have a member named 'text'

出口:

@IBOutlet var numField: WKInterfaceLabel!

导致错误的相关代码块:

func updateDisplay() {
    // If the value is an integer, don't show a decimal point
    var iAcc = Int(accumulator)
    if accumulator - Double(iAcc) == 0 {
        numField.text = "\(iAcc)"
    } else {
        numField.text = "\(accumulator)"
    }

具体来说:

numField.text = "\(iAcc)"

numField.text = "\(accumulator)"

我已经尝试 optionals as suggested in other answers,但我仍然遇到问题。

来自the class reference

没有 属性 的文字。设置文字的方法是调用setText方法:

numField.setText("\(Acc)")

numField.setText("\(accumulator"))

标签没有text属性。你必须使用 setText 属性.

func updateDisplay() {
    // If the value is an integer, don't show a decimal point
    var iAcc = Int(accumulator)

    if accumulator - Double(iAcc) == 0 {
        numField.setText("\(iAcc)")
    } else {
        numField.setText("\(accumulator)")
    }
}

下面是WKInterfaceLabel class声明: