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 -> NSFileProviderItemParameters
- 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:
createdDirectoryItemA provider item that describes the newly created directory, 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 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
parentItemIdentifierparameter.- filename
Set to the value passed to the
directoryNameparameter.- 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
Providing support for user-driven actionsdeleteItem(withIdentifier:completionHandler:)importDocument(at:toParentItemIdentifier:completionHandler:)renameItem(withIdentifier:toName:completionHandler:)reparentItem(withIdentifier:toParentItemWithIdentifier:newName:completionHandler:)setFavoriteRank(_:forItemIdentifier:completionHandler:)setLastUsedDate(_:forItemIdentifier:completionHandler:)setTagData(_:forItemIdentifier:completionHandler:)trashItem(withIdentifier:completionHandler:)untrashItem(withIdentifier:toParentItemIdentifier:completionHandler:)