Type Method


Compiles a model on the device to update the model in your app.


+ (NSURL *)compileModelAtURL:(NSURL *)modelURL error:(NSError * _Nullable *)error;



The local file path to your downloaded .mlmodel file.

Return Value

The local file path to the compiled model (the .mlmodelc file).


The source .mlmodel file must be on the device. Pass the compiled model to modelWithContentsOfURL:error: to initialize an MLModel instance.

Listing 1

Compiling a model file and creating an MLModel instance from the compiled version

let compiledUrl = try MLModel.compileModel(at: modelUrl)
let model = try MLModel(contentsOf: compiledUrl)

Compiling can be time consuming and shouldn't be done on the main thread.

See Downloading and Compiling a Model on the User's Device for more details.

See Also

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software