1

I want to type an if statement in the InterfaceController which basically goes like-

if label.text == "Hello" {
//execute some code
}

But the WKInterfaceLabel just seems to have the setText() property. So how can I access the WKInterfaceLabel's text property? Thanks in advance!

R Menke
  • 8,183
  • 4
  • 35
  • 63
Krish Wadhwana
  • 1,544
  • 2
  • 12
  • 24
  • First step in answering every problem: google the class you have a problem with. That will always give you a link from apple with all available functions, variables and constants in a class. [WKInterfaceLabel class ref](https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceLabel_class/) – R Menke Sep 05 '15 at 16:15

1 Answers1

2

Short answer: You can't.

Longer answer, store the string in a separate variable and use that for the if statements.

class InterfaceController: WKInterfaceController {

    @IBOutlet var myLabel: WKInterfaceLabel!
    var myString : String = ""

    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)

        myString = "hello"
        myLabel.setText(myString)

        if myString == "hello" {

            //so awesome stuff here

        }
        // Configure interface objects here.
    }

    override func willActivate() {
        // This method is called when watch view controller is about to be visible to user
        super.willActivate()
    }

    override func didDeactivate() {
        // This method is called when watch view controller is no longer visible
        super.didDeactivate()
    }

}
R Menke
  • 8,183
  • 4
  • 35
  • 63