Contents

createDirectory(withName:inParentItemIdentifier:completionHandler:)

Creates a directory with the given name inside the given parent directory.

Declaration

func createDirectory(withName directoryName: String, inParentItemIdentifier parentItemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping  @Sendable (NSFileProviderItem?, (any Error)?) -> Void)
func createDirectory(withName directoryName: String, inParentItemIdentifier parentItemIdentifier: NSFileProviderItemIdentifier) async throws -> NSFileProviderItem

Parameters

  • directoryName:

    The name of the directory to be created.

  • parentItemIdentifier:

    The persistent identifier for the parent directory.

  • completionHandler:

    A block that takes the following parameters:

    createdDirectoryItem

    A provider item that describes the newly created directory, 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 creates a directory. Override this method to create the directory 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 createdDirectoryItem instance that you pass to the completion handler must define the following properties:

itemIdentifier

This identifier may be temporary. If you later receive a permanent identifier from your server, delete the temporary item and add the permanent one.

parentItemIdentifier

Set to the value passed to the parentItemIdentifier parameter.

filename

Set to the value passed to the directoryName parameter.

creationDate

Set to the current date and time.

typeIdentifier

Set to public.folder.

childItemCount

Set to 0.

capabilities

Set to define the actions that the user can perform on the directory (for example, allowsAddingSubItems, allowsReading, and allowsWriting).

The user’s ability to create a directory is controlled by the parent directory’s allowsAddingSubItems capability.

See Also

Handling actions