Type ‘MLModel’ has no member ‘__loadContents’ error on xcode 12

Reference

https://stackoverflow.com/questions/63917164/ml-build-error-for-catalyst-xcode-12-gm

Symptom

Type ‘MLModel’ has no member ‘__loadContents’ error occurred on Xcode 12

Cause

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

Solution

  1. In your targets build settings you can set COREML_CODEGEN_LANGUAGE to “None”
  2. Open terminal then go to where your .mlmodel folder
  3. Type “xcrun coremlcompiler generate <YourModel.mlmodel> –language Swift .”
  4. This will create <YourModel.swift> file in same folder.
  5. Open Xcode and add <YourModel.swift> in your project.
  6. Click <YourModel.swift> and comment out method that compiler complains.

In my case, I commented out the following two functions, recompiled the project again and it worked fine.

//    class func load(configuration: MLModelConfiguration = MLModelConfiguration(), completionHandler handler: @escaping (Swift.Result<CatDog100, 

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

投稿者: admin

Free Software Engineer

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です