在任何目标中都找不到 "Content View Previews"的Xcode 12.3 SwiftUI Preview 1

标签 xcode swiftui

我看到其他人在 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/

相关文章:

ios - 基于内容的具有 PageTabViewStyle 动态高度的 SwiftUI TabView

ios - 使用 Xcode 6.0.1 构建后,Game Center 无法识别应用程序

ios - 我可以用动画围绕中心旋转 UIImage 吗?

SwiftUI:调整弹出窗口的大小以适合

SwiftUI View 在意想不到的路径上动画

ios - SwiftUI - 如何覆盖嵌套的偏移/位置动画?

swift - 如何使用 SwiftUI 显示 UIImage?

xcode - 根据里面的信息扩展ScrollView并保存?

xcode - iOS:popViewController 意外行为

objective-c - 正在设置 NSString 但在从另一个类调用时显示为空 - iOS