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).
\nIn 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.
\nLike this:
\n(selected iPhone SE2 but automatically chooses iPhone14 Pro)\n
Press control and option, click previewDevice
, and then select an available model in the inspector can fix it\xef\xbc\x9a
(iPhone 14 selected, preview shows as expected)\n
If there is no model you want in these options, you can add it in the menu Window -> Devices and Simulators first.
\nHope this helps you.
\n