<!--
{
  "availability" : [
    "macOS: 15.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSPasteboard/detectedMetadata(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "s:So12NSPasteboardC6AppKitE16detectedMetadata3forAbCE08DetectedE0VShys14PartialKeyPathCyAGGG_tYaKF"
  },
  "title" : "detectedMetadata(for:)"
}
-->

# detectedMetadata(for:)

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

```
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`](/documentation/AppKit/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`](/documentation/AppKit/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:

```swift
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).")
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)