Apple Documentation on WatchKit (through API Reference): https://developer.apple.com/reference/watchkit
Getting familiar with Xcode: Xcode Interface
Like iOS where you use
@IBAction , here you could use them too.
Let's say we have a button which when clicked changes the label's text to something else.
To get started:
WKInterfaceLabel and a
WKInterfaceLabel to the
Ctrl-Drag from the
InterfaceController.swift and enter the details as shown in the following picture to add an outlet property:
InterfaceController.swiftand enter the details as shown in the following picture to add an action method:
[[self outputLabel] setText:@"Button Tapped!"]
To develop an application for watchOS, you should start with Xcode. Xcode only runs on macOS. At the time of writing, the latest version is Xcode 8.3.
If you want to start a new project from scratch:
Boot up your Mac and install Xcode from the App Store if it's not already installed.
Choose to create a new project.
In templates, choose watchOS and then "iOS App with WatchKit App".
If you already have an iOS project and want to add a watchOS target:
Each watchOS target includes an App and an Extension. App contains the UI stuff and Extension contains the actual logic (similar to Views and Models in MVC architecture in iOS).
Each WatchKit App has a
Interface.storyboard file which you design the app in it, and a
Assets.xcassets file to put your assets in.
Each WatchKit Extension has a
InterfaceController.swift file (actually a
WKInterfaceController subclass) which is similar to the
ViewController file in iOS.
To make a Hello World app:
Open up the
Locate the main
Apple Watch simulator will eventually show up with your app running.