<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FileProvider",
  "identifier" : "/documentation/FileProvider/NSFileProviderEnumerating/enumerator(for:request:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "File Provider"
    ],
    "preciseIdentifier" : "c:objc(pl)NSFileProviderEnumerating(im)enumeratorForContainerItemIdentifier:request:error:"
  },
  "title" : "enumerator(for:request:)"
}
-->

# enumerator(for:request:)

Tells the file provider to return an enumerator for the provided directory.

```
func enumerator(for containerItemIdentifier: NSFileProviderItemIdentifier, request: NSFileProviderRequest) throws -> any NSFileProviderEnumerator
```

## Parameters

`containerItemIdentifier`

The item identifier for the directory.

`request`

An object that identifies the context of that request, such as the requesting app.

## Return Value

An enumerator for the specified directory.

## Discussion

The system calls this method to request an enumerator for the specified item.

Possible item identifiers include:

- [`rootContainer`](/documentation/FileProvider/NSFileProviderItemIdentifier/rootContainer): The system passes this identifier when the user begins browsing your file provider’s content.
- A directory’s [`itemIdentifier`](/documentation/FileProvider/NSFileProviderItemProtocol/itemIdentifier): The system requests a new enumerator each time the user opens a new directory.
- [`workingSet`](/documentation/FileProvider/NSFileProviderItemIdentifier/workingSet): The system can request an enumerator so that it can sync the working set in the background.
- A document’s [`itemIdentifier`](/documentation/FileProvider/NSFileProviderItemProtocol/itemIdentifier): The system subscribes to live updates by requesting an enumerator for a document.
- The [`trashContainer`](/documentation/FileProvider/NSFileProviderItemIdentifier/trashContainer) directory.: The system passes this identifier when the user browses the contents of the trash. If your File Provider extension doesn’t support moving items to the trash, your implementation should throw or return an error.

Your implementation should create and return an [`NSFileProviderEnumerator`](/documentation/FileProvider/NSFileProviderEnumerator) object that provides the requested content.

### Handle Errors

If you can’t return the requested enumerator, you must throw an error in Swift, or if you return nil in Objective-C, you must set the `error` out parameter.

If the `containerItemIdentifier` parameter is [`trashContainer`](/documentation/FileProvider/NSFileProviderItemIdentifier/trashContainer) and your extension doesn’t support trashing items, then it should fail with the <doc://com.apple.documentation/documentation/Foundation/NSFeatureUnsupportedError-swift.var> error code from the <doc://com.apple.documentation/documentation/Foundation/NSCocoaErrorDomain> domain. Additionally, make sure the items managed by your File Provider extension don’t have the [`allowsTrashing`](/documentation/FileProvider/NSFileProviderItemCapabilities/allowsTrashing) capability enabled.

If the `containerItemIdentifier` parameter doesn’t exist in your remote storage, you should fail with an [`NSFileProviderError.Code.noSuchItem`](/documentation/FileProvider/NSFileProviderError/Code/noSuchItem) error. The system then attempts to delete the item from disk.

If you pass [`NSFileProviderError.Code.notAuthenticated`](/documentation/FileProvider/NSFileProviderError/Code/notAuthenticated) or [`NSFileProviderError.Code.serverUnreachable`](/documentation/FileProvider/NSFileProviderError/Code/serverUnreachable) to the handler, the system presents an appropriate alert to the user, but doesn’t try to access the metadata until triggered again by the user.

The system considers any other errors to be transient, and automatically retries the method call.

---

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)