Reputation: 27437
How to render a SwiftUI view inside Xcode Playground? PreviewProvider
does not seem to work with Swift Playground.
struct FooView: View {
var body: some View {
Text("Foo")
}
}
struct SampleView: PreviewProvider {
static var previews: some View {
FooView()
}
}
Upvotes: 3
Views: 1113
Reputation: 27437
PlaygroundPage
from PlaygroundSupport
is what needed to render a SwiftUI view.
import SwiftUI
import PlaygroundSupport
struct FooView: View {
var body: some View {
Text("Foo")
}
}
PlaygroundPage.current.setLiveView(FooView())
and as @cbjeukendrup mentioned this also works with Playgrounds on iPadOS.
Upvotes: 10