Class

NSItemProvider

An NSItemProvider object provides a lazy and secure way to convey data between a host app and extension. An item provider object wraps data such as text, images, or URLs and stores type information to help processes identify that data. When you actually want the data in an item provider, you load it asynchronously, which gives the item provider time to transfer it from another process as needed.

Overview

An extension typically encounters item providers when examining the attachments property of an NSExtensionItem object. During that examination, the extension can use the hasItemConformingToTypeIdentifier(_:) method to look for data that it recognizes. Item providers use Uniform Type Identifier (UTI) values to identify the data they contain. After finding a type of data that your extension can use, it calls the loadItem(forTypeIdentifier:options:completionHandler:) method to load the actual data, which is delivered to the provided completion handler.

You can create item providers to vend data to another process. An extension that modifies an original data item can create a new NSItemProvider object to send back to the host app. When creating data items, you specify your data object and the type of that object. You can optionally use the previewImageHandler property to generate a preview image for your data.

A single item provider may use custom blocks to provide its data in many different formats. When configuring an item provider, use the registerItem(forTypeIdentifier:loadHandler:) method to register your blocks and the formats each one supports. When a client requests data in a particular format, the item provider executes the corresponding block, which is then responsible for coercing the data to the appropriate type and returning it to the client.

Symbols

Initializing an Item Provider

init?(contentsOf: URL!)

Initializes and returns an item provider with the contents of the specified file.

init(item: NSSecureCoding?, typeIdentifier: String?)

Initializes and returns an item provider with the specified object and type information.

Registering Custom Coercion Handlers

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

Registers a block for providing the data in the specified format.

var registeredTypeIdentifiers: [Any]

An array of the types supported by the item provider.

Getting the Item’s Data

func hasItemConformingToTypeIdentifier(String)

Returns a Boolean value that indicates whether the item provider has data of the given type.

Generating a Preview Image

var previewImageHandler: NSItemProvider.LoadHandler?

The custom preview image handler block to use with this item provider.

Getting the Visual Attributes

var sourceFrame: NSRect

The rectangle (in screen coordinates) occupied by the item in the host app’s source window.

var containerFrame: NSRect

The rectangle (in screen coordinates) of the item’s visible content.

var preferredPresentationSize: NSSize

The ideal presentation size of the item.

Constants

CompletionHandler

A block that receives the item provider’s data.

LoadHandler

A block that loads the item provider’s data and coerces it to the specified type.

Options Dictionary Key

Keys indicating options to use when generating the item provider’s data.

Keys for Items Accessed in JavaScript Code

Keys used in property list items received from or sent to JavaScript code.

Relationships

Inherits From