预览设备未显示在预览中

Mar*_*ark 8 preview swiftui

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

但是,该设备未在预览中显示。我xcrun simctl list devicetypes在终端中运行了“”,它确实显示了模拟器。这是正常行为还是我错过了什么。我的目标是展示该应用程序在 iPhone 分辨率下的外观。我正在使用 xCode 13。

在此输入图像描述

iDe*_*Orz 18

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

\n

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.

\n

Like this:

\n

(selected iPhone SE2 but automatically chooses iPhone14 Pro)\n在此输入图像描述

\n

Press control and option, click previewDevice, and then select an available model in the inspector can fix it\xef\xbc\x9a

\n

(iPhone 14 selected, preview shows as expected)\n在此输入图像描述

\n

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

\n

Hope this helps you.

\n