Contents

DataDetection

Access and utilize common types of data that the data detection system matches.

Overview

Data detection methods in other frameworks detect common types of data represented in text, and return DataDetection framework classes that provide semantic meaning for matches. Get relevant, domain-specific information from matches of the following types:

  • Calendar events

  • Email addresses

  • Flight numbers

  • Web links

  • Amounts of money, with currencies

  • Phone numbers

  • Postal addresses

  • Shipment tracking numbers

Use functions, such as those in UIPasteboard, to detect the types of data that you specify in a particular context. For example, find email addresses in a pasteboard using detectValues(for:completionHandler:) as this example shows:

UIPasteboard.general.detectValues(for: [\.emailAddresses]) { [self] result in
    switch result {
    case .success(let detectedValues):
        guard let firstEmailAddressMatch = detectedValues.emailAddresses.first else {
            return
        }
        let newEmailAddress = firstEmailAddressMatch.emailAddress
        let newLabel = firstEmailAddressMatch.label
        addNewEmail(for: contact, address: newEmailAddress, label: newLabel)
    case .failure(let error):
        print("Error detecting email addresses: \(error.localizedDescription)")
    }
}

Then, inspect and use the data from objects that the data detection system returns.

Topics

Matched strings

Matched data types

Pasteboard detectors