Here is my code to detect URL in a text
let detector: NSDataDetector = try NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
let matches: [NSTextCheckingResult] = detector.matches(in: message!, options: NSRegularExpression.MatchingOptions.init(rawValue: 0), range: NSMakeRange(0, (message?.count)!))
var url: URL?
for item in matches {
let match = item as NSTextCheckingResult
url = match.url
print(url!)
break
}
However, this code makes www.example.com as http://example.com
What I want is to get this URL as HTTPS like https://example.com
How can I achieve that?
There's no API to tell
NSDataDetectorto default tohttpsURL schemes when it finds a URL with no scheme.One option is to update the resulting URL yourself: