Why You Should Use SwiftUI for Developing Apple Watch Apps
SwiftUI might not be ready for complex iPhone apps, but it is ready for almost any watchOS app
by
Lou Franco
My Apple Watch app, Sprint-o-Mat, was originally an iPhone/Watch app combination because, at that time, a Watch app needed to be paired with an iPhone app.
Then, 3 months after I started, Apple changed everything about Apple Watch app development.
SwiftUI completely changed WatchKit Development, so I threw out my app
At WWDC 2019, we learned two things:
- Watch apps could now be completely independent of iPhone apps
- SwiftUI, a new declarative UI framework, would also work directly on the watch.
I kept working on Sprint-o-Mat, but I didn't work on the UI or watch app any more as I knew that I would be adopting SwiftUI when it was released in September. Instead I concentrated on the parts that would not change: the non-UI code like HealthKit, CoreLocation, and workout logic code.
In September 2019, I got Xcode 11, iOS 13, watchOS 6 and started learning SwiftUI. This attempt failed (somewhat).
2019 was too early for SwiftUI on the watch
Frankly, in 2019, SwiftUI and Xcode were not ready, even for my app. So, I kept working on the other parts and made a UI good enough for me to test the app (it guides me during my running workouts and was good enough for me—the testing helped me learn the ins and outs of HealthKit development, which I'll share soon)
I did ultimately release a version right before WWDC 2020 with my simple UI. But, I eagerly awaited the next version.
Today, SwiftUI is good enough for almost any watch app
Xcode 12 and watchOS 7 are not perfect, but they are much better than their immediate predecessors and are about as capable as pre-SwiftUI WatchKit. (Slight aside: Apple has completely changed how watch development works a couple of times—SwiftUI represents their third attempt)
I am confident that adopting SwiftUI for any new Apple Watch app is the right decision. I would even recommend rewrites for most Watch apps that are pre-SwiftUI.
This is not true for iOS apps on the iPhone—it really depends on what you are doing and how important the exact UI is. If you are willing to make concessions to SwiftUI, and your UI can mostly be made from stock SwiftUI components, then it might be fine.
But, on the watch, even though there are some small limitations, the benefits are overwhelming.
Why I think you'll love SwiftUI in your WatchKit app
I'll be writing articles covering all of these topics, but here's a preview of what you can expect if you adopt SwiftUI and Combine to develop your Apple Watch app.
-
UI coding productivity: The combination of SwiftUI and Xcode previews, although not 100% stable, is a big boon to productivity.
-
Asynchronous/reactive code is easier to get right: The combination of SwiftUI and Combine (and Swift generally) makes creating correct code much easier. My watch app is dealing with a ton of asynchronously updated information (time, distance, heartbeats, and location) -- and crashing during a workout is unacceptable.
-
Legacy WatchKit wasn't great: Before SwiftUI, WatchKit development was complex and required much more XIB usage (if you don't know what that means, you should be glad). The XIB isn't totally gone, but you barely need to look at it. Everything about Apple Watch development in 2018 was second class and weird—now almost all of the UI code is exactly how you'd write it on any Apple platform.
-
You get to use SwiftUI in production now, without compromise: Since I don't think SwiftUI should be used on my iPhone projects yet, working on a Watch app gives me a way to learn production-ready SwiftUI on an app that benefits from it. I get to learn and use the style of code that I am sure will eventually be mainstream on iOS too.
-
The market has matured an extra year: watchOS 6.0 is good enough to still be your deployment target, so you get to target a version that's been out for more than a year. This also means that there's also a year's more worth of StackOverflow answers and tutorials.
Here's what you can do to get started right now
I'm working on more articles, but if you can't wait, here's how to get started.
-
Download the latest Xcode. I'll be using at least 12.4
-
If you don't know Swift, check out my series of articles that provide exercises for the official Apple Swift Programming Language book. If you know a similar language, you can get through this very quickly.
-
Learn about watchOS SwiftUI from WWDC 2019: Watch this 30 minute video on SwiftUI on the Apple Watch. It's a little out-of-date, so don't try to code along. But, it's good to give you an idea of what Watch development with SwiftUI is like.
-
Make some sketches: I made Sprint-o-Mat because I was very particular about my running workouts and wanted a customized app to guide me. If you have a particular way of working out that the built-in app Workouts app doesn't support, you could make some sketches to get started. I blogged about how developing a specific visualization on my watch helped guide my run.
In the next article I will get you started with an app and go through basic watch-oriented SwiftUI and Xcode previews. Then, we'll move onto the various navigation styles.
Subscribe to be notified of the next WatchKit article
This is the first article in a series on WatchKit development with SwiftUI. In it, I'll cover everything you need to know to make a workout app for Apple Watch. Make sure to sign up to my newsletter to get notified when a new article is published.
Contact me if you are working on a Watch app and need help.
Next Article: Apple Watch SwiftUI App Tutorial: Creating the Project