<!--
{
  "availability" : [
    "iOS: 11.0.0 - 27.0.0",
    "iPadOS: 11.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.13.0 - 27.0.0",
    "tvOS: 11.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "CoreML",
  "identifier" : "/documentation/CoreML/MLModel/compileModel(at:)-6442s",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core ML",
      "CoreML"
    ],
    "preciseIdentifier" : "c:objc(cs)MLModel(cm)compileModelAtURL:error:"
  },
  "title" : "compileModel(at:)"
}
-->

# compileModel(at:)

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

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

## Parameters

`modelURL`

The local file path to your downloaded `.mlmodel` file.

## Return Value

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

## Discussion

The source `.mlmodel` file must be on the device. Pass the compiled model to `MLModel/init(contentsOf:)` to initialize an `MLModel` instance.

Listing 1. Compiling a model file and creating an `MLModel` instance from the compiled version

```swift
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 <doc:downloading-and-compiling-a-model-on-the-user-s-device> for more details.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)