Search code examples
swiftuipreview

PreviewDevice not showing up in preview


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
            .previewDevice(PreviewDevice(rawValue: "iPhone 11"))
    }
}

However, the device is not shown in the preview. I ran "xcrun simctl list devicetypes" in terminal which does show the simulator. Is this normal behavior or am I missing something. The goal is that I want to show how the app looks with the iPhone resolution. I am using xCode 13.

enter image description here


Solution

  • I have meet same issue at Xcode Version 14.1 (14B47b).

    In my case ,this is because an unavailable simulator model has been selected like "iPhone 11",Xcode automatically chooses a available preview device based on your currently selected run destination.

    Like this:

    (selected iPhone SE2 but automatically chooses iPhone14 Pro) enter image description here

    Press control and option, click previewDevice, and then select an available model in the inspector can fix it:

    (iPhone 14 selected, preview shows as expected) enter image description here

    If there is no model you want in these options, you can add it in the menu Window -> Devices and Simulators first.

    Hope this helps you.