内容预览器未在 Xcode 12.5.1 上加载 [英] Content Previewer not loading on Xcode 12.5.1

查看:33
本文介绍了内容预览器未在 Xcode 12.5.1 上加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前几天我正在处理一个项目,但我的预览停止工作.我收到错误编译失败,找不到数据类型"在范围内"(所有代码/关系将在下面显示).我已经重新启动了几次 XCode,甚至注释掉了该区域的代码,但它仍然无法正常工作,是否还有其他人遇到此问题,我该如何解决?

I was working on a project the other day, and my preview stopped working. I got the error "Compiling Failed, cannot find "DataType" in scope" (all code/relationships will be shown below). I have restarted XCode a few times, and even commented out that area of code but it continues to not work, is anyone else having this problem and how can I fix it?

我正在预览一个名为Profile Sheet"的表单,它只是一个标准的 swiftUI 视图,因此预览代码如下所示:

I am previewing a sheet called "Profile Sheet", just a standard swiftUI View, so the preview code looks like:

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ProfileSheet()
    }
}

在配置文件中,它从与我的模型文件(不同的结构、不同的文件)、它使用的函数以及定义DataType"的函数关联的静态函数访问数据,有问题的泛型在这里:

In the profile sheet, it is accessing data from a static function associated with my model file (different struct, different file), the functions it is using, and the ones that define "DataType", the problematic generic are here:

static func saveData<DataType>(data: DataType, for key: String) {
        defaults.setValue(data, forKey: key)
    }
    
static func retrieveData<DataType>(defaultValue: DataType, for key: String) -> DataType {
        guard let value = defaults.value(forKey: key) as? DataType else {return defaultValue}
        return value
    }
    
static func saveComplexData<DataType>(data: DataType, for key: String) where DataType: Codable {
        let encodedData = try! JSONEncoder().encode(data)
        defaults.setValue(encodedData, forKey: key)
    }

static func retrieveComplexData<DataType>(defaultValue: DataType, for key: String) ->  DataType where DataType: Codable {
        guard let retrievedData = defaults.value(forKey: key) as? Data else { return defaultValue}
        let decodedData = try! JSONDecoder().decode(DataType.self, from: retrievedData)
        return decodedData

    }

所有这些功能都按预期运行,并且显然可以编译.即使当我运行以启动预览器并编译我的应用程序时,它也能正确构建,只有当它尝试启动预览模拟器时才如此.

all of these function as intended, and obviously compile. Even when I run to launch the previewer and compiles my app does it builder properly, its only when it is then trying to launch the preview simulator.

最后,我认为 Id 完全删除了这些函数,只是尝试显示一个与它们没有联系的视图,所以我预览了 Text("test") 并得到了同样的错误.

Finally, I thought Id remove those functions entirely and just try to display a View that has no connection to them, so I previewed Text("test") and got the same error.

在 Xcode 13 beta 3 &4 我能够运行模拟器,但我不能只在那些测试版上工作,因为它们仍然相当不稳定.

on Xcode 13 beta 3 & 4 I am able to run the simulator, but I cannot work only on those betas as they are still fairly unstable.

感谢任何帮助:)

推荐答案

我看到框架有很多奇怪的行为,我认为是由于对模拟器进行了更改以支持 Apple 芯片.我的临时解决方法是在我的应用程序/扩展目标中添加arm64"为模拟器构建时设置为 Excluded Architectures 构建设置(正如您的预览似乎正在尝试做的那样),并设置Build Active Architecture Only"为所有方案为否.可能值得一试.

I've seen quite a bit of weird behavior with frameworks, I think due to changes to the simulators to support Apple silicon. My temporary workaround is, in my app/extension targets, to add "arm64" to the Excluded Architectures build setting when building for the simulator (as your preview appears to be trying to do), and setting "Build Active Architecture Only" to No for all schemes. Might be worth a try.

根据苹果开发者答案中的三元组.

试试看https://developer.apple.com/forums/thread/657913

我相信这不是您的代码的问题,而是 Xcode 的问题,因为 Apple 硅 mac.尝试进行软件更新并重新安装 Xcode.

I believe it's not an issue with your code it's an issue with Xcode due to apple silicon macs. try to do a software update and reinstall the Xcode.

这篇关于内容预览器未在 Xcode 12.5.1 上加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆