<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: 1.0.0 - 1.1.0",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreML",
  "identifier" : "/documentation/CoreML/MLModelCollection/beginAccessingModelCollectionWithIdentifier:completionHandler:",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core ML"
    ],
    "preciseIdentifier" : "c:objc(cs)MLModelCollection(cm)beginAccessingModelCollectionWithIdentifier:completionHandler:"
  },
  "title" : "beginAccessingModelCollectionWithIdentifier:completionHandler:"
}
-->

# beginAccessingModelCollectionWithIdentifier:completionHandler:

Requests access to a model collection.

```
+ (NSProgress *) beginAccessingModelCollectionWithIdentifier:(NSString *) identifier completionHandler:(void (^)(MLModelCollection *modelCollection, NSError *error)) completionHandler;
```

## Parameters

`identifier`

The name of the model collection.

`completionHandler`

In Objective-C, the block that Core ML calls when the model collections is available to your app.

    The block has the following parameters:

- model: An [`MLModelCollection`](/documentation/CoreML/MLModelCollection) instance if the collection loaded successfully.
- error: An <doc://com.apple.documentation/documentation/Foundation/NSError> instance if the model collection failed to load (see [`MLModelError.Code`](/documentation/CoreML/MLModelError-swift.struct/Code)).

## Discussion

Use this method to access a model collection from a deployment (see `Creating and Deploying a Model Collection`). Your app can call this method multiple times, typically each time it needs to access the models in the collection.

```objc
[MLModelCollection beginAccessingModelCollectionWithIdentifier: modelCollectionName
                                             completionHandler:^(MLModelCollection * _Nullable modelCollection,
                                                                 NSError * _Nullable error) {
    if (nil != error) {
        [self reportError:error];
        return;
    }

    NSLog(@"Model collection `%@` is now available.", modelCollection.identifier);

    // Load a model from the collection.
    [self loadModelWithIdentifier:@"DeploymentModel"
                   fromCollection: modelCollection];
}];
```

Core ML calls your completion app’s completion handler once the entire collection is on the user’s device. If the model collection isn’t already on the user’s device, Core ML immediately begins fetching it over the network.

```swift
func modelCollectionAvailable(result: Result<MLModelCollection, Error>) {
    switch result {
    case .success(let collection):
        print("Model collection `\(collection.identifier)` is now available.")
        
        // Load a model from the collection.
        loadModel("DeploymentModel", from: collection)
        
    case .failure(let error):
        print("Error accessing a model collection: \(error)")
    }
}
```

Once your app has the model collection, use the model’s identifier that you assigned it in the deployment (see `Creating and Deploying a Model Collection`).

```objc
- (void)loadModelWithIdentifier:(NSString*) modelName
                 fromCollection:(MLModelCollection*) modelCollection {
    MLModelCollectionEntry* entry = modelCollection.entries[modelName];

    if (nil == entry) {
        NSLog(@"Couldn't find model `%@` in the `%@`.", modelName, modelCollection.identifier);
        return;
    }

    [MLModel loadContentsOfURL:entry.modelURL
                 configuration:[[MLModelConfiguration alloc] init]
             completionHandler:^(MLModel * _Nullable modelFromCollection,
                                 NSError * _Nullable error) {

        if (nil != error) {
            NSLog(@"Error loading model: %@", error);
            return;
        }

        // Use the `modelFromCollection` instance.
        // ...
    }];
}
```

Create an instance of a collection’s model by passing its entry’s `modelURL` — from the model collection’s [`entries`](/documentation/CoreML/MLModelCollection/entries) property — to the `load(contentsOf:configuration:completionHandler:)` class method.

> Tip:
> Use a default model from your app’s bundle while your app waits for the model collection. When your app gets the model collection, switch to the collection’s newer model.

If your app uses a default model from the app bundle, you can use an initializer from its convenience wrapper class that Xcode automatically generated.

```swift
let modelFromCollection = try? BuiltInModel(contentsOf: entry.modelURL)
```

---

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)