This tutorial gives you a chance to apply much of what you’ve already learned about SwiftUI, and — with little effort — migrate the Landmarks app to watchOS.
You’ll start by adding a watchOS target to your project, before copying over the shared data and views you created for the iOS app. With all of the assets in place, you’ll customize the SwiftUI views to display the detail and list views on watchOS.
Follow the steps to build this project, or download the finished project to explore on your own.
To create a watchOS app, start by adding a watchOS target to the project. Xcode adds groups and files for the watchOS app to your project, along with the schemes needed to build and run the app.
With the watchOS target set, you’ll need to share some resources from the iOS target. You’ll reuse the Landmark app’s data model, some resource files, as well as any views that both platforms can display without modification.
Now that the iOS target resources are in place for working on the watch app, you’ll need to create a watch-specific view for displaying landmark details. To test the detail view, you’ll create custom previews for the largest and smallest watch sizes, and make some changes to the circle view so everything fits on the watch face.
The
LandmarkList
that you created for iOS works for your watch app as well, and it automatically navigates to the watch-specific detail view that you just created when compiled for watchOS. Next, you’ll connect the list to the watch’sContentView
, so that it acts as the top level view for the watch app.
Your version of Landmarks for watchOS is almost complete. In this final section, you’ll create a notification interface that displays landmark information whenever you receive a notification indicating that you are close to one of your favorite locations.
Note This section only covers how to display the notification after you receive it. It doesn’t describe how to set up or send notifications.