<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreML",
  "identifier" : "/documentation/CoreML/MLModel/load(contentsOf:configuration:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core ML",
      "CoreML"
    ],
    "preciseIdentifier" : "s:So7MLModelC6CoreMLE4load10contentsOf13configuration17completionHandlery10Foundation3URLV_So0A13ConfigurationCys6ResultOyABs5Error_pGctFZ"
  },
  "title" : "load(contentsOf:configuration:completionHandler:)"
}
-->

# load(contentsOf:configuration:completionHandler:)

Creates a Core ML model instance asynchronously from a compiled model file, a custom configuration, and a completion handler.

```
class func load(contentsOf url: URL, configuration: MLModelConfiguration = MLModelConfiguration(), completionHandler handler: @escaping (Result<MLModel, any Error>) -> Void)
```

## Parameters

`url`

The path to a compiled model file (*ModelName*`.mlmodelc`), typically with the `URL` that [`compileModel(at:)`](/documentation/CoreML/MLModel/compileModel(at:)-6442s) returns.

`configuration`

The runtime settings for the new model instance.

`handler`

A closure the method calls when it finishes loading the model.

## Discussion

Use this method to load a model asynchronously. Core ML calls your completion handler after it successfully loads the model, or encounters an error attempting to load it.

```swift
MLModel.load(contentsOf: modelURL) { result in
    switch result {
    case .success(let loadedModel):
        print("Successfully loaded model `\(loadedModel)`.")

        // Use the loaded model for predictions.
        // ...

    case .failure(let error):
        print("Error loading model: \(error).")
    }
}
```

In Swift, if the model loaded successfully, you can use the instance from the <doc://com.apple.documentation/documentation/Swift/Result/success(_:)> associated value; otherwise, use the <doc://com.apple.documentation/documentation/Swift/Result/failure(_:)> associated value to address the error. In Objective-C, you can use the [`MLModel`](/documentation/CoreML/MLModel) instance in your completion hander; otherwise, use the <doc://com.apple.documentation/documentation/Foundation/NSError> instance to address the error.  See [`MLModelError.Code`](/documentation/CoreML/MLModelError-swift.struct/Code) for the list of error codes.

---

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)