Search code examples
iosswiftcoremlios14xcode12

ML Build error for Catalyst (Xcode 12 GM)


Anyone else having issues with the GM release with ML models and has a solution for this? I get the following error:

Type 'MLModel' has no member '__loadContents'

I have cleaned the Project + deleted derived data (this is a generated file that is put into the derived data folder)

I notice that the method should not be there for mac OS 10.15 which I use, but it there for some reason.

I also noticed that this API is still in beta while the GM is a production build? https://developer.apple.com/documentation/coreml/mlmodel

Should I regenerate the ML model?

xcode error


Solution

  • Root cause of this is :

    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

    Steps to fix :

    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 comment out :

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

    and

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

    methods to fix swift file.