WWDC 19
SwiftUI on watchOS
SwiftUI offers apps some capabilities that were not possible before, e.g. swipe to delete and reordering in lists, or an easy way to do custom graphics and animations
Fully integrated with WatchKit, both ways
SwiftUI allows you to use the same code on all platforms
However, Apple Watch is a very special platform; a watchOS app should not be just a tiny version of the iOS app, it should be specifically designed for the Watch by only picking the right elements of the experience
Building an Apple Watch app is building the whole experience, not just the main app, but also complications, notifications, Siri interface β depending on the app
Use subclasses of WKHostingController
to embed SwiftUI views in an interface controller that WatchKit can use
.font(.system(.headline, design: .rounded)
) β uses a rounded version of San Francisco
.listRowPlatterColor(topic.color)
β sets the color of the list cell background
.listStyle(.carousel)
β a list design which centers the currently focused item on the screen
.onMove { }
β enables drag to reorder
.onDelete { }
β enables swipe to delete
For notification UI, inherit from WKUserNotificationHostingController
When a notification is received (didReceive(_:)
), the view body is automatically invalidated and reloaded
Using digital crown:
Fluent scrolling between the beginning and the end:
.digitalCrownRotation($binding, from:, through:)
β lets you create some kind of custom scrollable container
Discrete values:
.digitalCrownRotation($binding, from:, through:, by:)
β for building interfaces where e.g. some value moves up or down by 1 when scrolling
Going around in a circle:
.digitalCrownRotation($binding, from:, through:, by:, sensitivity:, isContinuous: true)
β sensitivity says how fast it rotates
.focusable(true)
β lets the user switch focus between elements; digital crown events go to the focused item