NSItem 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.
- iOS 8.0+
- macOS 10.10+
- tvOS 8.0+
- watchOS 2.0+
An extension typically encounters item providers when examining the
attachments property of an
NSExtension object. During that examination, the extension can use the
has 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
load 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
NSItem 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
preview 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
register 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.