📅  最后修改于: 2022-03-11 14:56:25.934000             🧑  作者: Mango
let text = "http://www.google.com. http://www.bla.com"
func checkForUrls(text: String) -> [URL] {
let types: NSTextCheckingResult.CheckingType = .link
do {
let detector = try NSDataDetector(types: types.rawValue)
let matches = detector.matches(in: text, options: .reportCompletion, range: NSMakeRange(0, text.count))
return matches.compactMap({$0.url})
} catch let error {
debugPrint(error.localizedDescription)
}
return []
}
checkForUrls(text: text)