Articles, podcasts and news about Swift development, by John Sundell.

Using SwiftUI in a playground

Published on 13 Jun 2019
Discover page available: SwiftUI

You can totally start learning and experimenting with SwiftUI in an Xcode playground. Just import PlaygroundSupport, and assign a UIHostingController as your live view:

import SwiftUI
import PlaygroundSupport

struct MyView: View {
    var body: some View {
        Text("Hello, world!")
    }
}

let vc = UIHostingController(rootView: MyView())
PlaygroundPage.current.liveView = vc

Support Swift by Sundell by checking out this sponsor:

Bitrise

Bitrise: My favorite continuous integration service. Automatically build, test and distribute your app on every Pull Request — which lets you quickly get feedback on each change that you make. Start 2021 with solid continuous integration from Bitrise, using hundreds of ready-to-use steps.