Book Image

Building Apple Watch Projects

By : Stuart Grimshaw
Book Image

Building Apple Watch Projects

By: Stuart Grimshaw

Overview of this book

With Apple’s eagerly anticipated entry into the wearable arena, the field is wide open for a new era of app development. The Apple Watch is one of the most important technologies of our time. This easy-to-understand book takes beginners on a delightful journey of discovering the features available to the developer, right up to the completion of medium-level projects ready for App Store submission. It provides the fastest way to develop real-world apps for the Apple Watch by teaching you the concepts of Watch UI, visual haptic and audio, message and data exchange between watch and phone, Web communication, and finally Visual, haptic as well as audio feedback for users. By the end of this book, you will have developed at least four fully functioning apps for deployment on watchOS 2.
Table of Contents (17 chapters)
Building Apple Watch Projects
About the Author
About the Reviewer

Writing the code

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


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 applicationContext: [String : AnyObject]) {

Don't be alarmed by the error warning that Xcode shows about the dataManager; this is only happening because we haven't yet written the...