Starting with Xcode 6.3 and WatchKit

With the official release of Xcode 6.3 (8 April 2015), including WatchKit and Swift 1.2, I've decided to make ThisMany available also for Apple Watch. An app like ThisMany should be ideal for the watch.

The first step was to upgrade my version of Xcode from 6.1.1 to 6.3—easily done—and then compile the app to make sure that everything was still agreeing with the new version of Swift. Unfortunately, the code didn't compile. But fortunately Xcode can be very helpful giving you "Fix-it" hints on how to solve your compilation issues. I found that all my compilation errors, except one, were due to the new as! operator that was introduced in Swift 1.2. Before 1.2 the as operator was used for both upcasting and downcasting. But in Swift 1.2 these conversions are separated in two operators. The as operator is still used for upcasting, or guaranteed conversion, but the as! operator is now used for downcasting, or forced conversion.  Apple has an informative post about these changes in their very useful Swift Blog: The as! Operator.

The other compilation error that I found was in the auto-generated code when you create an app with Core Data enabled. To fix that I simply created a new app with Core Data enabled, compared the auto-generated code from Xcode 6.1.1 with the one from Xcode 6.3, and upgraded my old code accordingly. Easy fix.

With everything compiling and running as expected, the next step was to configure my Xcode project for WatchKit. To do this, again, I referred to Apple's documentation about developing for Apple Watch: Configuring Your Xcode Project. Basically, all you have to do is to add a WatchKit app target to your existing iOS app project. Xcode adds to your project a WatchKit Extension, which runs on the iPhone, and a WatchKit app, which runs on the Apple Watch. Easy. Lets compile again. Error.

This time I got an error in Xcode with this:

error: WatchKit apps must have a deployment target equal to iOS 8.2 (was 8.3)

It seems—I thought—that WatchKit wants the deployment target of my project to be 8.2 and not 8.3. So, I changed it in the project Info page, but still it didn't compile, and I got again the same error. What am I missing? This time, I went to the Build Settings of all my targets, not just the project, and changed the iOS Deployment Target for all of them to iOS 8.2. Success. Now everything compiles.

Well, this is just the beginning. I am just starting with this. Next, I need to go through more Apple documentation and see how to layout a proper Apple Watch UI, and connect everything to my app.

Fun times ahead.