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

# detectedValues(for:)

Determines whether the first pasteboard item matches the specified patterns, reading the contents if it finds a match.

```
func detectedValues(for keyPaths: Set<PartialKeyPath<NSPasteboard.DetectedValues>>) async throws -> NSPasteboard.DetectedValues
```

## Parameters

`keyPaths`

The patterns to detect on the pasteboard.

## Return Value

An [`NSPasteboard.DetectedValues`](/documentation/AppKit/NSPasteboard/DetectedValues) instance containing the values for the patterns found on the pasteboard.

## Discussion

For details about the types returned for each pattern, see [`NSPasteboard.DetectedValues`](/documentation/AppKit/NSPasteboard/DetectedValues).

The following example shows how to use this method to find links in the first pasteboard item:

```swift
do {
    let valueResults = try await NSPasteboard.general.detectedValues(for: [\.links])
    let links = valueResults.links
    guard !links.isEmpty else {
        print ("No links found in item.")
        return
    }
    for link in links {
        print("Link retrieved: \(link.url).")
    }
} catch {
    print("Error: \(error).")
}
```

> Important: When calling this method, if a match is found, the system informs the person using the app that the app is trying to read the contents of the pasteboard. If the person denies access to the pasteboard, the method throws an 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)