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

# detectedPatterns(for:)

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

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

## Parameters

`keyPaths`

The patterns to detect on the pasteboard item.

## Return Value

A set with the patterns found on the pasteboard item.

## Discussion

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

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

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