Contents

detectedMetadata(for:)

Determines available metadata from the specified metadata types for the first pasteboard item, without notifying the person using the app.

Declaration

func detectedMetadata(for keyPaths: Set<PartialKeyPath<NSPasteboard.DetectedMetadata>>) async throws -> NSPasteboard.DetectedMetadata

Parameters

  • keyPaths:

    The metadata types to detect on the pasteboard.

Return Value

An NSPasteboard.DetectedMetadata instance containing the metadata for the metadata types found on the pasteboard.

Discussion

This method only gives access to limited types of metadata and doesn’t allow the app to access the contents. As a result, the system doesn’t notify the person using the app about reading the contents of the pasteboard.

For details about the metadata returned for each type, see NSPasteboard.DetectedMetadata.

The following example shows how to use this method to find the content type of a file reference in the first item on the pasteboard:

do {
    let metadataResults = try await NSPasteboard.general.detectedMetadata(for:     /// [\.contentType])
    if let contentType = metadataResults.contentType {
        print("Content type is: \(contentType.identifier).")
    } else {
        print("Couldn't get content type.")
    }
} catch {
    print("Error: \(error).")
}

See Also

Detecting patterns and metadata in pasteboard items