detectedPatterns(for:)
Determines whether the first pasteboard item matches the specified patterns, without notifying the person using the app.
Declaration
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:
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).")
}