Catalyst 的 ML 构建错误 (Xcode 12 GM)

ML Build error for Catalyst (Xcode 12 GM)

还有其他人对带有 ML 模型的 GM 版本有疑问并且有解决方案吗?我收到以下错误:

Type 'MLModel' has no member '__loadContents'

我清理了项目+删除了派生数据(这是生成的文件,放到派生数据文件夹)

我注意到该方法不应该用于我使用的 mac OS 10.15,但由于某种原因它在那里。

我还注意到这个 API 仍处于测试阶段,而 GM 是生产版本? https://developer.apple.com/documentation/coreml/mlmodel

我应该重新生成 ML 模型吗?

根本原因是:

CoreML compiler in Xcode 12.0 GM is generating code that has symbols available only on macOS BigSur causing the compilation issue. If the goal is to build a catalyst or macOS-only app with Xcode 12.0

修复步骤:

  1. 在您的目标构建设置中,您可以将 COREML_CODEGEN_LANGUAGE 设置为“None”
  2. 打开终端然后转到您的 .mlmodel 文件夹
  3. 输入“xcrun coremlcompiler generate --language Swift .”
  4. 这将在同一文件夹中创建 文件。
  5. 打开 Xcode 并在您的项目中添加
  6. 单击 并注释掉编译器抱怨的方法。

就我而言,我注释掉了:

class func load(contentsOf modelURL: URL, configuration: MLModelConfiguration = MLModelConfiguration(), completionHandler handler: @escaping (Swift.Result<Nudity, Error>) -> Void)

class func load(configuration: MLModelConfiguration = MLModelConfiguration(), completionHandler handler: @escaping (Swift.Result<Nudity, Error>) -> Void)

修复 swift 文件的方法。