Contents

reparentItem(withIdentifier:toParentItemWithIdentifier:newName:completionHandler:)

Moves the specified item into the given parent directory.

Declaration

func reparentItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, toParentItemWithIdentifier parentItemIdentifier: NSFileProviderItemIdentifier, newName: String?, completionHandler: @escaping  @Sendable (NSFileProviderItem?, (any Error)?) -> Void)
func reparentItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, toParentItemWithIdentifier parentItemIdentifier: NSFileProviderItemIdentifier, newName: String?) async throws -> NSFileProviderItem

Parameters

  • itemIdentifier:

    The item’s persistent identifier.

  • parentItemIdentifier:

    The persistent identifier for the new parent directory.

  • newName:

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

  • completionHandler:

    A block that takes the following parameters:

    reparentedItem

    A file provider item that represents the reparented 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

This method is called when the user moves a document or directory. Override this method to make any necessary local changes to the item and both its old and new parents. 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 reparentedItem instance that you pass to the completion handler should match the item’s old file provider item, with only one change: set the parentItemIdentifier property to the value passed to the parentItemIdentifier parameter.

The user’s ability to rename an item is controlled by the item’s allowsRenaming capability.

See Also

Handling actions