这是我在文本中检测 URL 的代码
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
}
但是,此代码使 www.example.com 成为http://example.com
我想要的是将此 URL 作为 HTTPS 获取,例如https://example.com
我怎样才能做到这一点?