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


Although we have created the file GameLogic.swift file, we have not actually created the class yet (this is different to Objective C)

Create the GameLogic class

Below the import Foundation statement that is part of the template, add the following code:

import Foundation

class GameLogic {


Plan the class

We will create a class that will encapsulate the code that deals with the game itself in isolation from the user interface. The GameLogic class doesn't need to know anything about interactions with the user, that is something that will be taken care of by the InterfaceController class, so let's first think about what we will need it to do, so that we can start to plan which methods we will need to implement.

We need it to do the following:

  • Create and maintain a sequence of colors and add a random color to it when required

  • Evaluate whether a player's tap on a color is a correct answer

  • Provide information as to whether the game is still in play or finished

  • Clear the data that collects during...