<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FileProvider",
  "identifier" : "/documentation/FileProvider/NSFileProviderManager/evictItem(identifier:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "File Provider",
      "FileProvider"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileProviderManager(im)evictItemWithIdentifier:completionHandler:"
  },
  "title" : "evictItem(identifier:completionHandler:)"
}
-->

# evictItem(identifier:completionHandler:)

Asks the system to remove an item from its cache.

```
func evictItem(identifier itemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping @Sendable ((any Error)?) -> Void)
```

## Parameters

`itemIdentifier`

The item’s identifier.

`completionHandler`

A block that the system calls after removing the item from disk. The system passes the following parameter:

- `error`: If an error occurs, this object contains information about the error; otherwise, it’s `nil`.

## Discussion

> Important:
> You can call this method from synchronous code using a completion handler, as shown on this page, or you can call it as an asynchronous method that has the following declaration:
> 
> ```swift
> func evictItem(identifier itemIdentifier: NSFileProviderItemIdentifier) async throws
> ```
> 
> For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/Swift/calling-objective-c-apis-asynchronously>.

Calling this method turns a materialized item into a dataless item to free up disk space. For more information on materialized and dataless items, see [Synchronizing the File Provider Extension](/documentation/FileProvider/synchronizing-the-file-provider-extension).

If the item is a document without local changes, this method deletes the local copy of the item’s content. If the item has local changes, it fails with an <doc://com.apple.documentation/documentation/Foundation/NSFileWriteNoPermissionError-swift.var> error.

When called on a directory, the system recursively evicts the directory’s content. It deletes the content of any materialized files, and recursively evicts any subdirectories. After it has successfully evicted all the content, it deletes its list of the directory’s content, making the directory dataless. The next time the system accesses the directory, it requests a list of the contents using the [`NSFileProviderEnumerating`](/documentation/FileProvider/NSFileProviderEnumerating) protocol.

If the system encounters a nonevictable child, eviction stops immediately, and the system calls the completion handler with a [`NSFileProviderError.Code.nonEvictableChildren`](/documentation/FileProvider/NSFileProviderError/Code/nonEvictableChildren) error. The error includes information about the nonevictable child in its <doc://com.apple.documentation/documentation/Foundation/NSError/underlyingErrors> property. The system may have evicted other materialized items, based on the traversal order.

The system calls the completion handler after it successfully evicts all items, or immediately when an error occurs. Eviction might fail with the following errors:

- [`NSFileProviderError.Code.unsyncedEdits`](/documentation/FileProvider/NSFileProviderError/Code/unsyncedEdits) if the item had nonuploaded changes.
- [`NSFileProviderError.Code.nonEvictable`](/documentation/FileProvider/NSFileProviderError/Code/nonEvictable) if the user has marked the item as nonevictable.
- `EBUSY` if the item has open file descriptors on it.
- `EMLINK` if the item has too many hardlinks.
- Other <doc://com.apple.documentation/documentation/Foundation/NSPOSIXErrorDomain> error codes if the system can’t access or manipulate the corresponding file.

---

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)