Using previews in UIKit
If you love the ease with which you can preview UI changes, but you are only working on UIKit projects, rest easy as you can also use this great feature while building UIKit apps.
In this recipe, we will learn how to wrap a UIViewController
and UIView
into SwiftUI views and then use live previews.
Getting ready
Clone or download the code for this book from GitHub: https://github.com/PacktPublishing/SwiftUI-Cookbook-2nd-Edition.
How to do it
We will check the app's build settings to ensure that iOS 13+ capabilities are enabled in the debug build. We'll then create a generic struct
that can be used to preview any UIKit ViewController
in the Xcode canvas. The steps are as follows:
- Go to this chapter's code in GitHub. For this recipe, open the Xcode project located in the
StartingPoint
file. - Click on the PreviewUIKitViews project file in the Xcode navigation pane, select Build Settings, scroll down to the Deployment section...