SWIFT: Why is “NSURL(string:” returning with Nil, even though it's a valid url in a browser?

后端 未结 4 725
旧巷少年郎
旧巷少年郎 2021-01-13 05:02

The first two example links are working the third one returns NIL.

Why is NSUrl returning nil for such string, even though it\'s a valid url in a browser?

Am

4条回答
  •  庸人自扰
    2021-01-13 05:35

    For swift3 you can do like this

    let url = URL(string:url.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)!)!
    

提交回复
热议问题