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

# detectedPatterns(for:)

Determines whether the first pasteboard item matches the specified patterns, without notifying the person using the app.

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

## Parameters

`keyPaths`

The patterns to detect on the pasteboard.

## Return Value

A set with the patterns found on the pasteboard.

## Discussion

This method only gives an indication of whether the first pasteboard item matches a particular pattern, 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.

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

```swift
do {
    let patternResults = try await NSPasteboard.general.detectedPatterns(for: [\.calendarEvents])
    if patternResults.contains(\.calendarEvents) {
        print("Calendar event(s) detected.")
    } else {
        print("Didn't detect any calendar events.")
    }
} 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)