XCode with can preview SwiftUI code on Canvas for many environments and devices with the help of PreviewProvider.
Like this:
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
ContentView()
.environment((\.horizontalSizeClass), .compact)
ContentView()
.previewDevice(PreviewDevice(stringLiteral: "iPad8,5"))
.environment((\.horizontalSizeClass), .regular)
}
}
}
How can we do the same in Playground? The following .previewDevice() modifier has no effect in Playground (XCode 12.0.1).
PlaygroundPage.current.setLiveView(ContentView().previewDevice(PreviewDevice(stringLiteral: "iPhone 7")))
Maybe it can be done somehow with PlaygroundPage.current.liveView or else?