How to Develop Apple Watch Apps with WatchKit
Tutorials about Apple Watch development with WatchKit, SwiftUI, and other related watchOS frameworks.
Why You Should Use SwiftUI for Developing Apple Watch Apps
Xcode 12 and watchOS 7 are not perfect, but they are much better than their immediate predecessors and I would say are about as capable as pre-SwiftUI WatchKit. I am confident that adopting this for any new Apple Watch app is the right decision.
Apple Watch SwiftUI App Tutorial: Creating the Project
This tutorial will use Xcode to make a minimal Apple Watch app. But, before you move on, it's a good idea to understand what it did so that you'll know how to add to it later.
Apple Watch App SwiftUI Simple Example Views
If you already tried out SwiftUI on the iPhone, most of what you know works the same on the watch. If you haven't, here are simple recreations of user interfaces in two of the built-in Apple Watch apps.
Apple WatchKit Breathe Animation Tutorial
In the last article, we drew the initial state of the the Breathe app. Now let's learn how to animate it.
How to use NavigationLink in a SwiftUI Watch App
In iOS, we use UINavigationViewController from UIKit to create a hierarchical navigation structure. Using it, we can push views onto the view controller stack, and we automatically get a back button to take us back.
UIKit and this class are not available to Apple watch developers, and so before SwiftUI, watch app developers used WKInterfaceController's pushController method and Storyboards.
Luckily, this is easier in SwiftUI.
Programmatic Navigation with NavigationLink on an Apple Watch
NavigationLink has built in functionality to manage the presentation and dismissal of the subview, and automatically puts a back button on the screen for you.
But, sometimes, there is a reason to send the user back to the calling view based on other things they do. In UIKit, we'd call dismiss, but in SwiftUI, we don't call methods on views to change them, we change state and let the view get re-rendered.
How to develop page based navigation UI on Apple Watch
On the Apple Watch, it's possible to have a set of screens that are peers to each other. You get to each page with left and right swipes. The bottom of the screen has a dot for each page in the set, with the current one lit up.
How to navigate from one page set to another in WatchKit
If you are targeting watchOS 6, and you have several possible root views, then you define each in a Storyboard and you need to navigate between them outside of SwiftUI.