Monday, October 23, 2023
HomeiOS Developmentios - #Preview (new macro) completely different gadgets programmatically in Xcode...

ios – #Preview (new macro) completely different gadgets programmatically in Xcode 15 Canvas with SwiftUI?


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.

enter image description here

Thanks upfront! The Lord All the time Delivers!



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments