我看到其他人在 Xcode 11 和 12 中使用 SwiftUI Previews 发布了问题,但在其他地方没有看到这个问题。
在 Xcode 11 中运行的旧项目在 Xcode 12 中加载,无论预览内容多么简单,都无法启动预览。
实际预览代码:
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Text("I heart Xcode")
.previewDevice("iPhone 11")
}
}
单击“继续”或“重试”后:CouldNotFindInputNodeInBuiltGraphError<XcodeGraphSource, PreviewInstance>: Preview 1 of "Content View Previews" not found in any targets
Preview 1 of "Content View Previews" must belong to at least one target in the current scheme in order to use previews
Element: PreviewInstance(destinationDescription: UVPreviewPipeline.AnyPreviewDestinationDescription(storage: UVPreviewPipeline.(unknown context at $1382211e0).AnyPreviewDestinationDescriptionBoxImpl<UVIntegration.SimulatorPreviewDestinationDescription>), previewIdentity: UVPreviewPipeline.PreviewIdentity(identifier: ContentView_Previews[0], description: contentType: Element contextType: application device: iPhone 11 index: 0 layout: device supportsLive: true supportsOnDevice: true), variant: nil, variantedIdentifier: ContentView_Previews[0], identifier: AnyHashable(ContentView_Previews[0]))
我只有一个目标,和以前一样,没有特殊配置。我试过重新加载 Xcode 以及将所有源文件复制到一个新目录(在某处看到那个)。
其他任何人都能够解析此错误消息或就如何修复 SwiftUI 预览提出建议?
谢谢。
最佳答案
一个偶然的机会,我意识到为什么预览在我的从头开始的项目中被破坏了。原因是我最初在安装过程中添加的“版本控制”构建阶段:xcrun agvtool next-version -all
将其包装到“预览”检查中之后,一切都很好:
if [ $ENABLE_PREVIEWS == "NO" ]
then
xcrun agvtool next-version -all
fi
关于在任何目标中都找不到 "Content View Previews"的Xcode 12.3 SwiftUI Preview 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65384298/