Instance Method

availableTypeFromArray:

Scans the specified types for a type that the receiver supports.

Declaration

- (NSPasteboardType)availableTypeFromArray:(NSArray<NSPasteboardType> *)types;

Parameters

types

An array of NSString objects specifying the pasteboard types your application supports, in preferred order.

Return Value

The first pasteboard type in types that is available on the pasteboard, or nil if the receiver does not contain any of the types in types.

Discussion

You use this method to determine the best representation available on the pasteboard. For example, if your application supports RTFD, RTF, and string data, then you might invoke the method as follows:

NSArray *supportedTypes =
    [NSArray arrayWithObjects: NSRTFDPboardType, NSRTFPboardType, NSStringPboardType, nil];
NSString *bestType = [[NSPasteboard generalPasteboard]
    availableTypeFromArray:supportedTypes];

If the pasteboard contains RTF and string data, then bestType would contain NSRTFPboardType. If the pasteboard contains none of the types in supportedTypes, then bestType would be nil.

You must send a types or availableTypeFromArray: message before reading any data from an NSPasteboard object. If you need to see if a type in the returned array matches a type string you have stored locally, use the isEqualToString: method to perform the comparison.

See Also

Validating Contents

- canReadItemWithDataConformingToTypes:

Returns a Boolean value that indicates whether the receiver contains any items that conform to the specified UTIs.

- canReadObjectForClasses:options:

Returns a Boolean value that indicates whether the receiver contains any items that can be represented as an instance of any class in a given array.

types

An array of the receiver’s supported data types.

+ typesFilterableTo:

Returns the data types that can be converted to the specified type using the available filter services.