Search code examples
swiftwatchkitwkinterfacelabel

How to get the text out of a WKInterfaceLabel


It seems that labels are a bit different on the Apple Watch!

I have the following label created :

@IBOutlet weak var playerNameLabel: WKInterfaceLabel!

Then writing the label is no problem (with the "setText" method)

let someString = "Hello"
playerNameLabel.setText(someString)

But how do I get the text out of such a Label into a String-constant ???

I tried:

let plaerName_firstTrial: String = playerNameLabel.description  // some weird stuff
let plaerName_secondTrial: String = playerNameLabel.text // error
let plaerName_thirdTrial: String = playerNameLabel // error
let plaerName_fourthTrial: String = ?????

Solution

  • WKInterfacLabel has only setter property and no getter property as defined by Apple.

    Check this WKInterfaceLabel class declaration :

    Screenshot for issue