user4882614
user4882614

Reputation:

How to get the contents of a label for WatchOS in Swift

I am trying to make an app for WatchOS, and I need to get the contents of a label in WatchOS using Xcode 7 with Swift.

For some reason I can't seem to use labelName.text

Upvotes: 2

Views: 1298

Answers (2)

Victor Sigler
Victor Sigler

Reputation: 23451

You can't get the text of a WKInterfaceLabel as you normally do in iOS yet!! as far I know. There are several ways to accomplish what you want but one of them is saving the text in your own variable before setting it on the WKInterfaceLabel and every time you change it, update the variable too like in the following way:

var textInLabel: String!

@IBOutlet var textLabel: WKInterfaceLabel!

func changeLabelText(text: String) {
    // save the text to get it later.
    self.textInLabel = text
    self.textLabel.setText(text)
}

I hope this helps you.

Upvotes: 2

Drewf
Drewf

Reputation: 414

From WKInterfaceObject documentation:

Communication between an interface object in your extension and the corresponding interface element in your Watch app is one way. You can set the values of an interface object, but you cannot get the current values. If you want to know the current value of an attribute, you must save the value yourself.

https://developer.apple.com/library/prerelease/watchos/documentation/WatchKit/Reference/WKInterfaceObject_class/

Upvotes: 1

Related Questions