/SwiftyDataDetector

Extensions to make the NSDataDetector more pleasant to work with.

Primary LanguageSwiftMIT LicenseMIT

SwiftyDataDetector

My attempt to use extensions and custom data types to make working with NSDataDetector more Swifty and pleasant. I have written a blog post about this.

For example you can construct it like this:

let detector = NSDataDetector(dataTypes: DataDetectorType.allCases)

And here is an example of using my enumerateMatches method:

detector.enumerateMatches(in: exampleText) { (range, match) in
    switch match {
    case .email(let email, let mailtoURL):
        print("Found email address: \(email)")
    case .phoneNumber(let number):
        print("Found phone number: \(number)")
    default:
        break
    }
}