There’s a new #Preview
macro (or a minimum of new to me). It is mentioned on the SwiftLee weblog right here. I am excepting a few of his code exampled beneath to ask my query.
To preview your code within the SwiftUI canvas you used to must code:
struct ContentView: View {
var physique: some View {
VStack {
Textual content("Hiya World!")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
…however now (October 2023) you’ll be able to code:
struct ContentView: View {
var physique: some View {
VStack {
Textual content("Hiya World!")
}
}
}
#Preview {
ContentView()
}
My query is: how can we re-code the next taking into consideration Apple’s #Preview
macro syntax so we will 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 allows you to manually change the displayed machine within the Canvas, however is there a method to programmatically do it.
Thanks upfront! The Lord All the time Delivers!