Created
October 26, 2018 09:31
-
-
Save iceboxi/3451770b3d93535a05b01de4ce25d6c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension String { | |
| public var isEmail: Bool { | |
| let dataDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) | |
| let firstMatch = dataDetector?.firstMatch(in: self, options: NSRegularExpression.MatchingOptions.reportCompletion, range: NSRange(location: 0, length: length())) | |
| return (firstMatch?.range.location != NSNotFound && firstMatch?.url?.scheme == "mailto") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment