Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

get links from string or html a tag swift

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)
Comment

PREVIOUS NEXT
Code Example
Swift :: Arithmetic Operators in Swift 
Swift :: Swift repeat...while Loop 
Swift :: Type Constraints in Swift Generics 
Swift :: image preprocessing in python 
Swift :: swift complete print function syntax 
Swift :: Swift Bitwise OR Operator 
Swift :: swift function parameters 
Swift :: Swift Nil-coalescing operator 
Swift :: didselectrowatindexpath not called swift 
Swift :: sprite kitYourNextScene 
Ruby :: ruby delete file 
Ruby :: If the version you need is missing, try upgrading ruby-build. linux 
Ruby :: ruby calculate execution time 
Ruby :: get current year in ruby 
Ruby :: ruby replace certain character 
Ruby :: rails validators 
Ruby :: Your Ruby version is 3.0.0, but your Gemfile specified 2.7.4 
Ruby :: FATAL: database does not exist rails 
Ruby :: ruby check if value in array 
Ruby :: ruby match word in string 
Ruby :: how to create 2 dimensional array in ruby 
Ruby :: ruby is character 
Ruby :: Rails validations: unique scope 
Ruby :: heroku run rails c 
Ruby :: ruby routes 
Ruby :: rails server not updating 
Ruby :: ruby abs function programming 
Ruby :: ruby function arguments 
Ruby :: ||= ruby 
Ruby :: ruby assign rest of array 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =