Apple Watch represents a new chapter in the relationship people have with technology. Now you can deliver innovative new experiences to your customers on their wrist. And by adding WatchKit, you can take your apps even further by extending and enhancing their functionality on Apple Watch.
Lets learn how to work with WatchKit by an Counter Example.
Create New Project in XCode with Swift Language
Add Apple Watch Target in your Application
Select Apple Watch Target
Select Options for Target
Storyborad of watch
By adding target you will find the InterfaceController.swift and Interface.storyboard
Design watch with the controls
Design and reposition the controls with the properties of controls.
Now Time to do some code and connect the outlets
Code:
[code language=”obj-c”]
// InterfaceController.swift
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController {
@IBOutlet weak var lblCounter: WKInterfaceLabel!
var counter:Int = 0
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
// 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()
}
@IBAction func upButtonPressed() {
counter = counter + 1
lblCounter.setText("\(counter)")
}
@IBAction func downButtonPressed() {
counter = counter – 1
lblCounter.setText("\(counter)")
}
}
[/code]
Download project with this stuff AppleWatchCounterDemo.zip
Thanks!
Happy Coding 😀