Mrugesh Tank
Mrugesh Tank

Reputation: 3560

retrieve the text of WKInterfaceLabel in swift

How can i get the text of label in Swift or Objective-C in WatchKit?
The class is not UILabel but it is WKInterfaceLabel.
I have also tried to search in class library of apple but there is only three methods are available.

Upvotes: 10

Views: 4727

Answers (3)

Jayprakash Dubey
Jayprakash Dubey

Reputation: 36447

Apple has declared WKInterfaceLabel class with only setter property and no getter property.

This screenshot shows class declaration of WKInterfaceLabel present in WatchKit framework.

Screenshot

Upvotes: 1

Grant Isom
Grant Isom

Reputation: 150

Just have a @property (nonatomic) NSString *currentText; That everytime you update or set your WKInterfaceLabel you also set or update.

It's not the best solution, but it works for now, while Apple doesn't have any official way to get it.

Upvotes: 4

Jageen
Jageen

Reputation: 6365

By reading reference it is not possible you have to maintain track which you set in label
looks like apple is very strict about this class you can not create a subclass or direct instance of this.
enter image description here
They only talk about how to set the text not about getting text
enter image description here

Non of it's supper class have method to get text
enter image description here
If its posible You can create extension of WKInterfaceLabel and get text
but no idea if apple approve it or not.

My Conclusion is
Its not possible directly by any way to get text
you can do some trick but make sure that its acceptable by apple.


Friendly speaking i am not much aware about watch SDK, but if you dealing with any beta version of type thing let hope that apple will add that thing in new version as they had wrote
enter image description here


Reference of all i wrote and images are here

Upvotes: 6

Related Questions