renameItem(withIdentifier:toName:completionHandler:)
Renames a document or directory.
Declaration
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 -> NSFileProviderItemParameters
- 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:
renamedItemA file provider item that represents the renamed item, or
nilif an error occurred.errorAn error object. If an error occurs, pass in an object that describes the error; otherwise, set it to
nil.
Discussion
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 property to the value passed to the itemName parameter.
The user’s ability to rename an item is controlled by the item’s allowsRenaming capability.
See Also
Handling actions
Providing support for user-driven actionscreateDirectory(withName:inParentItemIdentifier:completionHandler:)deleteItem(withIdentifier:completionHandler:)importDocument(at:toParentItemIdentifier:completionHandler:)reparentItem(withIdentifier:toParentItemWithIdentifier:newName:completionHandler:)setFavoriteRank(_:forItemIdentifier:completionHandler:)setLastUsedDate(_:forItemIdentifier:completionHandler:)setTagData(_:forItemIdentifier:completionHandler:)trashItem(withIdentifier:completionHandler:)untrashItem(withIdentifier:toParentItemIdentifier:completionHandler:)