O'Reilly logo

Building Apple Watch Projects by Stuart Grimshaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing the code

So, time to get some code written. We will start with some code that should look very familiar.

WatchConnectivity

Once again, we need to create a class that encapsulates all of the logic around communication with the outside world (or at least the part of the outside world that is squeezed into an iPhone).

WatchConnectivityManager class

In the project navigator, select the WatchConnectivity.swift file. Delete the import Foundation line from the code, and replace it with the following code:

import WatchConnectivity class WatchConnectivityManager: NSObject, WCSessionDelegate { static let sharedManager = WatchConnectivityManager() let dataManager = WatchDataManager.sharedManager private override init() { } func session(session: WCSession,didReceiveApplicationContext ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required