---
title: "evictItem(identifier:completionHandler:)"
framework: fileprovider
role: symbol
role_heading: Instance Method
path: "fileprovider/nsfileprovidermanager/evictitem(identifier:completionhandler:)"
---

# evictItem(identifier:completionHandler:)

Asks the system to remove an item from its cache.

## Declaration

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

```swift
func evictItem(identifier itemIdentifier: NSFileProviderItemIdentifier) async throws
```

## 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:

## Discussion

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: func evictItem(identifier itemIdentifier: NSFileProviderItemIdentifier) async throws For information about concurrency and asynchronous code in Swift, see 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. 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 NSFileWriteNoPermissionError 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 protocol. If the system encounters a nonevictable child, eviction stops immediately, and the system calls the completion handler with a NSFileProviderError.Code.nonEvictableChildren error. The error includes information about the nonevictable child in its 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 if the item had nonuploaded changes. 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 NSPOSIXErrorDomain error codes if the system can’t access or manipulate the corresponding file.

## See Also

### Working with items

- [reimportItems(below:completionHandler:)](fileprovider/nsfileprovidermanager/reimportitems(below:completionhandler:).md)
- [requestDownloadForItem(withIdentifier:requestedRange:)](fileprovider/nsfileprovidermanager/requestdownloadforitem(withidentifier:requestedrange:).md)
- [requestDownloadForItem(withIdentifier:requestedRange:completionHandler:)](fileprovider/nsfileprovidermanager/requestdownloadforitem(withidentifier:requestedrange:completionhandler:).md)
- [requestModification(of:forItemWithIdentifier:options:completionHandler:)](fileprovider/nsfileprovidermanager/requestmodification(of:foritemwithidentifier:options:completionhandler:).md)
- [enumeratorForMaterializedItems()](fileprovider/nsfileprovidermanager/enumeratorformaterializeditems().md)
- [enumeratorForPendingItems()](fileprovider/nsfileprovidermanager/enumeratorforpendingitems().md)
