Reputation:
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
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
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.
Upvotes: 1