There is a new #Preview
macro (or at least new to me). It's discussed on the SwiftLee blog here. I'm excepting some of his code exampled below to ask my question.
To preview your code in the SwiftUI canvas you used to have to code:
struct ContentView: View {
var body: some View {
VStack {
Text("Hello World!")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
...but now (October 2023) you can code:
struct ContentView: View {
var body: some View {
VStack {
Text("Hello World!")
}
}
}
#Preview {
ContentView()
}
My question is: how do we re-code the following taking into account Apple's #Preview
macro syntax so we can change the device-displayed-on-SwiftUI-LivePreview-Canvas programmatically:
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView().previewDevice(PreviewDevice(rawValue: "iPhone SE"))
}
}
The work-around I see is a dropdown graphical interface on the canvas the lets you manually change the displayed device in the Canvas, but is there a way to programmatically do it.
Thank you in advance! The Lord Always Delivers!
.previewDevice(PreviewDevice(rawValue: "iPhone SE"))
, can't you? – Dehisce