Contents

loadItem(forTypeIdentifier:options:completionHandler:)

Loads the item’s data and coerces it to the specified type.

Declaration

func loadItem(forTypeIdentifier typeIdentifier: String, options: [AnyHashable : Any]? = nil, completionHandler: NSItemProvider.CompletionHandler? = nil)
func loadItem(forTypeIdentifier typeIdentifier: String, options: [AnyHashable : Any]? = nil) async throws -> any NSSecureCoding

Parameters

  • typeIdentifier:

    A string that represents the desired UTI.

  • options:

    A dictionary of keys and values that provide information about the item, such as the size of an image. (See Nsitemproviderpreferredimagesizekey for a key you can use.)

  • completionHandler:

    A completion handler block to execute with the results. For information about the format of this block, see Completionhandler.

Discussion

Call this method when you want to retrieve the item provider’s data. If the item provider object is able to provide data in the requested type, it does so and asynchronously executes your completionHandler block with the results. The block may be executed on a background thread.

The type information for the first parameter of your completionHandler block should be set to the class of the expected type. For example, when requesting text data, you might set the type of the first parameter to NSString or NSAttributedString. An item provider can perform simple type conversions of the data to the class you specify, such as from NSURL to NSData or FileWrapper, or from NSData to UIImage (in iOS) or NSImage (in macOS). If the data could not be retrieved or coerced to the specified class, an error is passed to the completion block’s.

See Also

Loading the provider’s contents