Check if an URL has got http:// prefix

后端 未结 8 869
野的像风
野的像风 2021-02-07 08:45


In my application, when the user add an object, can also add a link for this object and then the link can be opened in a webView.
I tried to save a link without http://

8条回答
  •  半阙折子戏
    2021-02-07 08:55

    I wrote an extension for String in Swift, to see if url string got http or https

    extension String{
    
        func isValidForUrl()->Bool{
    
            if(self.hasPrefix("http") || self.hasPrefix("https")){
                return true
            }
            return false
        }
    }
    
    if(urlString.isValidForUrl())
        {
          //Do the thing here.
    }
    

提交回复
热议问题