我在Swift 1.2中使用了这个
let urlwithPercentEscapes = myurlstring.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
这给了我一个警告,要求我使用
stringByAddingPercentEncodingWithAllowedCharacters
我需要使用NSCharacterSet作为参数,但有这么多,我无法确定哪一个会给我与之前使用的方法相同的结果.
An example URL I want to use will be like this
http://www.mapquestapi.com/geocoding/v1/batch?key=YOUR_KEY_HERE&callback=renderBatch&location=Pottsville,PA&location=Red Lion&location=19036&location=1090 N Charlotte St, Lancaster, PA
用于编码的URL字符集似乎包含修剪集
URL的路径组件是紧跟在
然而,我不想削减它的任何方面.
但是当使用下面的方法时,就没有问题了.它用一些魔法对字符串进行了编码,我可以得到我的URL数据.
let urlwithPercentEscapes = myurlstring.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
事实上
使用给定的编码将字符串的表示形式返回给
谢谢