How To Use SwiftUI In Playground – WWDC2020

SwiftUI works easily for iOS apps and it’s the same with Swift Playground.

To use SwiftUI instead of UIKit, first import SwiftUI.

import SwiftUI

Then create a simple view.

struct MainView: View {
    var body: some View {
        Text(“SmashSwift”)
    }
}

The last step it to set liveView.

PlaygroundPage.current.setLiveView(MainView())

And that’s it. Now, you can write code in SwiftUI.