Xcode 12 ML Model Compatibility

I have a simple app built with Xcode 11.7; it uses 2 ML Models that were generated with Create ML tool. It builds and executes as expected.

After installing Xcode 12, when I try to build the app (without any changes), I get build failures with a message like this:

Type 'MLModel' has no member '__loadContents'

it appears twice (presumably once for each ML Model).

I tried re-generating the ML models with Create ML from Xcode 12 but that didn't eliminate the error messages. (If I do a CLEAN-PROJECT before building, still get the errors)

(Also, the Xcode 11.7 app still executes without problems)

Anyone else have this type of problem?

Replies

>without any changes

Suggest you always use the Product menu to clean build folder when opening a legacy project in a new version Xcode, and perform any 'fixes' that Xcode recommends.

Good luck.
thanks for the response; I had done the clean and updated recommended settings. In fact I created a new project and a new ML model and had the same problem. It seems that just including the model output from create ML without any references to it at all in the project code will cause the problem.
update on this issue: if I access the model by compiling and then loading it in the application that works; however getting prediction from compiled model is cumbersome because there is no wrapper class.

I guess I'll file a bug and see what happens.

For me it is easy to replicate the problem:

(1) Generate an image classifier with create ML tool in Xcode 12
(2) Create a simple Xcode project (such as a command line tool Swift project)
The project will compile and run
(3) Add the ML Model class from output of model generated in step (1) to the project
(4) Project now fails build process with the error given above
Here is a workaround:

Open the project in Xcode 11. Go to the auto-generated source file for your model. Copy and paste that into a new Swift source file and add this to your project. Disable source code auto-generation for Core ML models in the project settings.

Now open the project in Xcode 12 and it should no longer give that error.

thanks for the response with potential workaround. Unfortunately I do not have Xcode 11 around anymore as it was updated by install of Xcode 12. I guess I could re-download and install it alongside Xcode 12.

My own workaround was to simply access the external model file and compile and load it rather than including it in project. This seems to work fine. I did file a bug for this and received the following analysis in my feedback report:

"Investigation complete - Works as currently designed"

Extremely non-helpful.

(Also, I looked at project settings but do not see one for auto-generation of Core ML models)

Just an update; I was able to access a machine with Xcode 11 and performed the suggestions (copy class code from Xcode 11 and then disable ML Class code generation); it did build without error messages and worked properly.

However this still seems to me to be a bug in the Xcode 12 compiler for it to generate class wrapper code that has errors.

We root-caused this to a mismatch in SDKs in Xcode 12.0 GM. The official note on https://developer.apple.com/download/release/:

"Xcode 12 includes everything you need to create amazing apps for all Apple platforms. Includes the latest SDKs for iOS, watchOS, and tvOS, and macOS Catalina."

CoreML compiler in Xcode 12.0 GM is generating code that has symbols available only on macOS BigSur causing the compilation issue. This was fixed in Xcode 12.2 and above.