

/cdn.vox-cdn.com/uploads/chorus_image/image/65665165/apple_watch_app_900.0.jpg)
Navigating to another screen from the storyboard: If there are any crashes, double-check the identifier of the second view controller.

When you click the button, the second screen will be displayed. Switch to the WatchKit App scheme, and run the app. You probably have to downcast it to the desired type using as?, since AnyObject is too generic.Ĥ. In the second screen, you extract the data inside the awakeWithContext method. The context is of type AnyObject, so you can pass anything you want. For this simple tutorial, there is nothing to pass between the two screens, so I will set it to nil. The context parameter is used for passing data between the two screens. If you want a modal segue, add the following code: presentControllerWithName(“Your-second-screen-identifier”, context: nil). If you want a push segue, add the following code: pushControllerWithName(“Your-second-screen-identifier”, context: nil). The following codes may be added inside the new action:
#Control mac with apple watch code#
Select the first view controller, open the Assistant Editor, control + drag the button to the code file, set the Connection type to Action, give it a descriptive name, and click Connect.ģ. In this tutorial, I have named the target screen’s identifier SecondScreen.Ģ. In order to move to the second screen from code, you have to add an identifier for that view controller in the Attributes inspector. Navigating to the second screen from code:ġ. You can find the button and label objects in the Objects library. For the second one, add a label containing a unique message so that you know the second screen is being displayed. Please note that the code within this tutorial is written in Swift.īefore you follow this tutorial, create a new Xcode project, add the WatchKit target, and two interface controllers to the Interface.storyboard file under the WatchKit App target. You can do it from the storyboard or the code. An Apple Watch is very similar to its iPhone counterpart regarding how you navigate between screens.
