<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIPasteboard/detectPatterns(for:inItemSet:completionHandler:)-7ubl1",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "s:So12UIPasteboardC5UIKitE14detectPatterns3for9inItemSet17completionHandleryShys14PartialKeyPathCyAbCE14DetectedValuesVGG_10Foundation05IndexH0VSgys6ResultOySayAMGs5Error_pGctF"
  },
  "title" : "detectPatterns(for:inItemSet:completionHandler:)"
}
-->

# detectPatterns(for:inItemSet:completionHandler:)

Requests that the data detection system identify the patterns that you specify for the pasteboard items, and provide the patterns that it matches to your closure.

```
func detectPatterns(for keyPaths: Set<PartialKeyPath<UIPasteboard.DetectedValues>>, inItemSet itemSet: IndexSet?, completionHandler: @escaping (Result<[Set<PartialKeyPath<UIPasteboard.DetectedValues>>], any Error>) -> ())
```

## Parameters

`keyPaths`

A set of key paths you use to indicate which types of patterns you want the data detection system to match.

`itemSet`

A set of indexes you provide to indicate which pasteboard items the data detection system inspects to detect patterns.

`completionHandler`

A closure you provide to process patterns the data detection system matches, or to handle errors.

## Discussion

Because 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, the system doesn’t notify the user about reading the contents of the pasteboard.

---

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)