Creating Your First WatchKit Extension

The traditional first task in any development environment is the ubiquitous “Hello, World!” example. For an Apple Watch app, a good “Hello, World!” will get some text on the screen and react to a button being tapped, so let’s start there. Open Xcode and create a new Xcode project by selecting File New Project. From the left column under watchOS, select Application, and then select the iOS App with WatchKit App template and click Next. For the name of the project, let’s use HelloWatch. Next, Xcode wants an organization name and identifier. What should you use? The answer depends on how you want to test the app.

The examples in this book will use the organization name The Pragmatic Bookshelf with the identifier com.pragprog for these project settings, as shown in the following figure. If you want to test on a real Apple Watch, which we’ll go over later, you’ll need to use a unique identifier—only one Apple developer account can use the identifier com.pragprog.HelloWatch, and I’ve already claimed it.

For this project, I’ve used HelloWatch as the name and com.pragprog as the identifier, so the app’s bundle identifier is com.pragprog.HelloWatch. That will come in handy when it’s time to do the code signing. With these values set, make sure that the language is set to Swift—this app’s source code will be Swift only. Uncheck all of the check boxes underneath the language selection and click Next. Choose a location to save the project and click Create. Just like that, you have a watch app!

images/watch-app-template.png
Joe asks:
Joe asks:
Can I Hit “Build and Run” Yet?

Sure! But depending on your Xcode configuration, you might be surprised. The list of simulated devices in Xcode may not have any devices paired with a simulated Apple Watch. If you don’t see any simulators as a destination when you choose the HelloWatch WatchKit App scheme, you may need to create a new device. To do that, open Xcode’s Devices window by clicking Window Devices or pressing 2. Your list of devices will appear in the left column. Click the + at the bottom-left corner of the window to add a new device. Choose an iPhone 5 or later as the device, and you’ll be able to choose an Apple Watch size to go with it. Click Create, and your new device will appear in the Devices window, as well as a destination for the watch app scheme.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.96.224