Contents

setFavoriteRank(_:forItemIdentifier:completionHandler:)

Marks a directory as a favorite and sets its relative order in the Favorites list.

Declaration

func setFavoriteRank(_ favoriteRank: NSNumber?, forItemIdentifier itemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping  @Sendable (NSFileProviderItem?, (any Error)?) -> Void)
func setFavoriteRank(_ favoriteRank: NSNumber?, forItemIdentifier itemIdentifier: NSFileProviderItemIdentifier) async throws -> NSFileProviderItem

Parameters

  • favoriteRank:

    A value used to determine the relative order of directories in the Favorites list.

  • itemIdentifier:

    The item’s persistent identifier.

  • completionHandler:

    A block that takes the following parameters:

    favoriteItem

    A file provider item that represents the changed 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 marks a directory as a favorite. Override this method to make any necessary local changes. 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 favoriteItem instance that you pass to the completion handler should match the item’s old file provider item, with only one change: set the favoriteRank property with the value of the favoriteRank parameter.

Always include items with a non-nil favoriteRank property in your File Provider extension’s working set; however, you don’t need to include the directory’s content. You also don’t need to make the directory’s content available offline.

See Also

Handling actions