URL in Swift
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了URL in Swift相关的知识,希望对你有一定的参考价值。
When the url contains chinese encoding. You should convert it to UTF-8 encoding, otherwise it will be nil
1 let urlstring0 = "http://www.baidu.com/时间/地点/" 2 let urlstring1 = "http://www.baidu.com/abc/def" 3 4 let url0 = NSURL(string: urlstring0) 5 let url1 = NSURL(string: urlstring0.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!) 6 7 let url2 = NSURL(string: urlstring1) 8 let url3 = NSURL(string: urlstring1.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!) 9 let urlstring2 = String(url1!).stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
Result:
以上是关于URL in Swift的主要内容,如果未能解决你的问题,请参考以下文章
如何将这个 Objective-C 代码片段写入 Swift?