Pages

Tuesday, October 23, 2018

How to pass data between screen in watchOS?


Step - 1
From the viewcontroller pass the values in the
let value = "Val to pass on next page"
pushController(withName: "View", context: value)
Step - 2
In your second view controller
override func awake(withContext context: Any?) {
       super.awake(withContext: context)
       if let str = context as? String {
         print(str)
       }
}
Or
Step - 1
override func contextForSegue(withIdentifier segueIdentifier: String) -> Any? {
    if segueIdentifier == "secondViewID" {
        return "Val to pass on next page"
    }
}
Step - 2
In your second view controller
override func awake(withContext context: Any?) {
       super.awake(withContext: context)
       if let str = context as? String {
         print(str)
       }
}

No comments:

Post a Comment