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.


On return, if an error occurs, a pointer to an error information instance; otherwise nil.

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