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

# renameItem(withIdentifier:toName:completionHandler:)

Renames a document or directory.

```
func renameItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, toName itemName: String, completionHandler: @escaping @Sendable (NSFileProviderItem?, (any Error)?) -> Void)
```

```
func renameItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, toName itemName: String) async throws -> NSFileProviderItem
```

## Parameters

`itemIdentifier`

The item’s persistent identifier.

`itemName`

The new name of the file or directory, including the file extension.

`completionHandler`

A block that takes the following parameters:

- `renamedItem`: A file provider item that represents the renamed 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 renameItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, toName itemName: String) 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 renames a document or directory. Override this method to rename the item locally. 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 `renamedItem` instance that you pass to the completion handler should match the item’s old file provider item, with only one change: set the [`filename`](/documentation/FileProvider/NSFileProviderItemProtocol/filename) property to the value passed to the `itemName` parameter.

The user’s ability to rename an item is controlled by the item’s [`allowsRenaming`](/documentation/FileProvider/NSFileProviderItemCapabilities/allowsRenaming) 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)