Duplicating canvas preview

Hey guys,

Does any of you know how to duplicate the canvas preview window? There used to be a + sign on top of the canvas preview, but it’s no longer there in XCode 14.3

What do you mean by duplicate? Like show two different simulators in a single canvas?

Xcode has changed since that video was released.

Do the same thing that’s in Xcode to the left of the canvas

Add two different ContentViews in a Group in the preview, it does the same thing

In the more recent versions of Xcode you can do this:

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()

    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
        ContentView()
    }
}

and you will see this in your Xcode canvas view.

Each instance of ContentView is no longer stacked one above the other in the canvas. Now they are selectable by tapping where I have indicated 1 and 2.

To make the two different I have set 1 to be in dark mode via the button labelled 3.

This is the view with the second instance selected.

1 Like

Thank you very much for this, Chris!