ios - How to check an ability of swift to open URL? -


i'm trying images web , can't correctly check validity of url. code:

    var url = nsurl(string: self.linkurl)     if uiapplication.sharedapplication().canopenurl(url!) {         errorlabel.hidden = true         println(self.resulturl)         self.performseguewithidentifier("save", sender: self)     } else {         errorlabel.hidden = false     } 

it works if user pastes "https://www.google.com" doesn't if it's "www.google.com" or "google.com". i've tried:

    if var url = nsurl(string: self.linkurl) {         errorlabel.hidden = true         println(self.resulturl)         self.performseguewithidentifier("save", sender: self)     } else {         errorlabel.hidden = false     } 

it works if enter "https://www.google.com" on "www.google.com" , "google.com" code breaks further when i'm searching images in html. what's best way make work ?

www.google.com not valid url, because doesn't include protocol. best way make work check if self.linkurl starts http:// or https:// (using hasprefix()), , if not, prepend http://.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -