Yashar
Yashar

Reputation: 275

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

I'm working on an iWatch application and I'm getting the following error:

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

The outlet:

@IBOutlet var numField: WKInterfaceLabel!

Relevant code block which causes the error:

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)"
    }

Specifically:

numField.text = "\(iAcc)"

and

numField.text = "\(accumulator)"

I've tried optionals as suggested in other answers, but I am still having issues.

Upvotes: 3

Views: 2169

Answers (2)

Jayprakash Dubey
Jayprakash Dubey

Reputation: 36447

There is not text property for label. You've to use setText property.

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)")
    }
}

Below is WKInterfaceLabel class declaration:

Screenshot

Upvotes: 0

Naughty_Ottsel
Naughty_Ottsel

Reputation: 1103

From the class reference

There is no property for text. The way to set the text is to call the setText method:

numField.setText("\(Acc)")

or

numField.setText("\(accumulator"))

Upvotes: 10

Related Questions