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

# detectedMetadata(for:)

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

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

## Parameters

`keyPaths`

The metadata types to detect on the pasteboard item.

## Return Value

An [`NSPasteboard.DetectedMetadata`](/documentation/AppKit/NSPasteboard/DetectedMetadata) instance containing the metadata for the metadata types detected on the pasteboard item.

## Discussion

This method only gives access to limited types of metadata and doesn’t allow the app to access the item’s 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 iterate over each pasteboard item and, if the item is a URL that points to a file, get its content type with this method.

```swift
guard let pasteboardItems = NSPasteboard.general.pasteboardItems else { return }
for (index, item) in pasteboardItems.enumerated() {
    do {
        let metadataResults = try await item.detectedMetadata(for: [\.contentType])
        if let contentType = metadataResults.contentType {
            print("Item \(index) - Content type is: \(contentType.identifier).")
        } else {
            print("Item \(index) - Couldn't get content type.")
        }
    } catch {
        print("Item \(index) - 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)