---
title: "compileModel(at:)"
framework: coreml
role: symbol
role_heading: Type Method
path: "coreml/mlmodel/compilemodel(at:)-6442s"
---

# compileModel(at:)

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

## Declaration

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

## Parameters

- `modelURL`: The local file path to your downloaded .mlmodel file.

## Mentioned in

Downloading and Compiling a Model on the User’s Device

## Return Value

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

## Discussion

Discussion 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.
