Instance Method

registerItem(forTypeIdentifier:loadHandler:)

Lazily registers an item, according to the NSItemProvider type coercion policy.

Declaration

func registerItem(forTypeIdentifier typeIdentifier: String, loadHandler: @escaping NSItemProvider.LoadHandler)

Parameters

typeIdentifier

A string that represents the desired UTI.

loadHandler

A block capable of returning the data item as the specified type. For information about implementing this block, see NSItemProvider.LoadHandler.

Discussion

Use this method to register blocks that can take the item provider’s file or data object and convert it to a specific data format. Your loadHandler block is executed when a client passes the same typeIdentifier string to the loadItem(forTypeIdentifier:options:completionHandler:) method. In the implementation of your block, coerce the data to the specified type and call the provided completion handler. You must call the completion handler, either with the requested data or with an error.

Item providers know how to coerce known types of objects, such as images or strings. Use this method to register blocks to coerce your custom data types.

See Also

Registering Custom Coercion Handlers

var registeredTypeIdentifiers: [String]

Returns the array of type identifiers for the item provider, listed in the same order in which they were registered.