evictItem(identifier:completionHandler:)
Asks the system to remove an item from its cache.
Declaration
func evictItem(identifier itemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping @Sendable ((any Error)?) -> Void)func evictItem(identifier itemIdentifier: NSFileProviderItemIdentifier) async throwsParameters
- itemIdentifier:
The item’s identifier.
- completionHandler:
A block that the system calls after removing the item from disk. The system passes the following parameter:
errorIf an error occurs, this object contains information about the error; otherwise, it’s
nil.
Discussion
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.
EBUSYif the item has open file descriptors on it.EMLINKif the item has too many hardlinks.Other NSPOSIXErrorDomain error codes if the system can’t access or manipulate the corresponding file.