Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 746
Mrugesh Tank Avatar asked Dec 13 '14 06:12

Mrugesh Tank


3 Answers

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

like image 107
Jayprakash Dubey Avatar answered Nov 15 '22 17:11

Jayprakash Dubey


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
like image 43
Jageen Avatar answered Nov 15 '22 18:11

Jageen


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.

like image 41
Grant Isom Avatar answered Nov 15 '22 17:11

Grant Isom