Create your app’s user interface by programmatically composing single-responsibility views.
SwiftUI is a declarative framework for building user interfaces on all of Apple’s platforms. You can create rich user interfaces by composing single-responsibility views into larger, more complex layouts. Your app describes the correct layout for your view based on your its current state. SwiftUI detects changes to the state, and updates the views accordingly.
On watchOS, SwiftUI also gives you considerably more flexibility than storyboard-based layouts. For example,
List has a number of features that aren’t supported by
WKInterface, such as the platter style, swipe actions, and row reordering.
Additionally, you can preview your SwiftUI code in Xcode’s canvas. You can design, build, and test your interfaces without ever running your app.
To learn more about SwiftUI, see Learn to Make Apps Using SwiftUI. For more information, see SwiftUI.
Combine SwiftUI and Storyboards
WKHosting to host an SwiftUI view in an interface controller:
WKHosting and override its
body property to return a SwiftUI view. You can add the controller to your project’s storyboard, and present it, just like any other interface controller.
You can also use
WKInterface to create an SwiftUI view that displays and manages WatchKit interface objects.
Create a structure that adopts the
WKInterface protocol. Implement the
make method to instantiate and return an interface object. Implement the
update method to update the interface object whenever changes occur.
For most interface objects, this protocol is not necessary. Just create the SwiftUI version of the object. For example,
Button creates a
WKInterface in watchOS. However, interface objects that don’t have a corresponding SwiftUI view, such as
WKInterface, use the interface object’s SwiftUI initializer to programmatically create the object and return it in your