Let's get started!
Step 1:
Open xCode select File > New Project > Single View Application
Step 2:
Name your application appropriately and finish the project setup.
Now time to create the WatchKit part of your app. Go to File > New Target > iOS > Apple Watch > WatchKit App. (If a modal comes up click the Activate button).
Step 3:
You will see that xCode has created two new folders. The first folder is your WatchKit extension this is where all your code goes, the second is your WatchKit app where the app interface is managed. As you can see the extension contains an initial interface controller and the app contains a storyboard file.
Step 4:
Lets add something to our first app! Go into the Interface.Storyboard and see the initial interface controller. Drag a label from the object menu in the bottom right hand corner onto the interface.
Step 5:
Lets position the label in the middle of the interface. Click on the label and set the vertical and horizontal position to centre.
Step 6:
Time to link the label up to the InterfaceController. Open up the InterfaceController.h file on the right and control drag from the label to the file (this should feel fairly familiar if you are already using storyboards). Name the label and see your new outlet.
Step 7:
Dive into the InterfaceController.m and see three default WKInterfaceController methods.
– (void)awakeWithContext:(id)context
AwakeWithContext is the equivalent to init in a normal view controller, context is an id of an object that can be parsed into the controller when it is initialised.
– (void)willActivate
WillActive is the equivalent of ViewWillAppear in a UIViewController.
– (void)didDeactivate
DidDeactivate is the equivalent of ViewDidDisappear in a UIViewController.
In the WillActivate method set the label text.
[self.myFirstLabel setText:@“Hello World!”];
Step 8:
To run the WatchKit app select it in the xCode target drop down and click Run.
Step 9:
Navigate to the simulator and see your first Watchkit app running! (Pro tip: if you get stuck in infinite loading indicator mode where the loading indicator never goes away, just stop and start the simulator 3 times the third run will work……beta software).
What next?
Have a play with your new project and see what you can make! I will be writing more Dev tutorials on creating WatchKit apps covering WKInterfaceTable, WKInterfaceGroup, WatchKit Navigation and hopefully many more.
Published on 11 February 2015, last updated on 9 April 2019