Search code examples
swiftswift-playgroundcoreml

iOS 11 framework (CoreML) inside Playground Book


I recently encountered a strange behavior of Playground Books when trying to access the CoreML framework.

First of all, CoreML does work with pure .playground files, as can be seen in Apple's example "MarsHabitatModel".

When copying the same source files inside a .playgroundbook, the Playground Book failed to compile and raises

Error: MLModel is only available on iOS application extension 11.0 or newer.

I ensured that the deployment target inside Manifest.plist file of the .playgroundbook was set to iOS11.0. Because of that, I am very unsure of whether or how CoreML can work inside a Playground Book.

Has anyone of you successfully integrated an iOS11 framework inside a playground book?


Solution

  • Solution: Write @available(iOS 11.0, *) in front of all classes that use CoreML in your .playgroundbook

    Explanation: Apparently, the .playgroundbook is compiled for older iOS versions despite having set the deployment target to iOS11 inside the Manifest.plist. Using the @available prefix you can manually exclude your classes from being compiled for older versions.