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

# untrashItem(withIdentifier:toParentItemIdentifier:completionHandler:)

Moves an item out of the trash.

```
func untrashItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, toParentItemIdentifier parentItemIdentifier: NSFileProviderItemIdentifier?, completionHandler: @escaping @Sendable (NSFileProviderItem?, (any Error)?) -> Void)
```

## Parameters

`itemIdentifier`

The item’s persistent identifier.

`parentItemIdentifier`

The persistent identifier for the new parent directory, or `nil`.

`completionHandler`

A block that takes the following parameters:

- `untrashedItem`: A file provider item that represents the changed item, or `nil` if an error occurred.
- `error`: An error object. If an error occurs, pass in an object that describes the error; otherwise, set it to `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 untrashItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, toParentItemIdentifier parentItemIdentifier: NSFileProviderItemIdentifier?) async throws -> NSFileProviderItem
> ```
> 
> For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/Swift/calling-objective-c-apis-asynchronously>.

This method is called when the user removes a document or directory from the trash. Override this method to make any necessary local changes to remove the item from the trash, including updates to the working set. Your implementation should return immediately. Call the completion handler before performing any network activity or other long-running tasks. Defer these tasks to the background. The `untrashedItem` instance that you pass to the completion handler should match the item’s old file provider item, with only one change: set the item’s [`isTrashed`](/documentation/FileProvider/NSFileProviderItemProtocol/isTrashed) property to <doc://com.apple.documentation/documentation/Swift/false>.

If the `parentItemIdentifier` parameter is not `nil`, move the item to the specified parent. Otherwise, return it to its previous location (before being trashed). Undo any other changes that were made when the item was trashed.

The user’s ability to remove an item from the trash is controlled by the new parent directory’s [`allowsAddingSubItems`](/documentation/FileProvider/NSFileProviderItemCapabilities/allowsAddingSubItems) capability.

---

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)