Type Method


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


class func compileModel(at modelURL: URL) throws -> URL



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 init(contentsOf:) 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