detectedValues(for:)
Determines whether the first pasteboard item matches the specified patterns, reading the contents if it finds a match.
Declaration
func detectedValues(for keyPaths: Set<PartialKeyPath<NSPasteboard.DetectedValues>>) async throws -> NSPasteboard.DetectedValuesParameters
- keyPaths:
The patterns to detect on the pasteboard.
Return Value
An 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.
The following example shows how to use this method to find links in the first pasteboard item:
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).")
}