How to Use Live Previews in UIKit

Avoid endless Xcode builds on your UIKit projects

Finsi Ennes
The Startup

--

SwiftUI has changed the way of writing UI code but let’s be honest, most of iOS apps still use UIKit as framework. Migration to SwiftUI will be slow but meanwhile we can use some of its amazing tools, such as Live Previews.

In this tutorial you will learn how to wrap UIViewController and UIView into SwiftUI views in order to use Live Previews. Result will be the following:

Preview for UIViewController

If we want to add an UIViewController object into a SwiftUI interface, then we are going to need the UIViewControllerRepresentable protocol.

Start by creating a SwiftUI view that conforms such protocol:

Our struct will accept () -> UIViewController as closure:

--

--

Finsi Ennes
The Startup

iOS Developer. Passionate about coding and UX design. For more content, you can follow me on Instagram @finsi.code