This is both a heads-up to other developers, and a request for workarounds:
I noticed that the CoreML image segmentation model in my app crashes when compiling the app with Xcode 13 and running it on an iOS 14 device.
Compiling the same app and model with Xcode 12 the compiled CoreML model works just fine when running on the same devices.
The crash seems to be caused by CoreML trying to access the MLShapedArray type, which was only introduced in iOS 15 (see stack trace in screenshot).
So if you have an app using CoreML, make sure you test on iOS 14 devices before submitting a new build using Xcode 13.
For Apple folks, I filed a Feedback on this a little while ago (and of course heard nothing back). The ID is 9584636.
I had hoped this issue would get fixed before the Xcode 13 release, but unfortunately it is still there in the GM build.
Any workarounds (aside from 'keep using Xcode 12') would be appreciated.
Thank you for the report. We confirmed it was a problem in the model access code generator. Until we address the issue in an upcoming Xcode, a workaround is:
- Open the current model access code by selecting the .mlmodel file and clicking “Model Class” and exporting it to keep.
- In “Target Membership”, select “No Generated Classes”.
- Add the saved code-gen Swift file in step 1 back to the project.
- Remove lazy properties with MLShapedArray . If you need these properties, you can change to a computed property.