URLEncode和URLDecode
2018-05-17 本文已影响0人
开洋_shen
URLEncode
extension String {
// URL Decode
func URLDecode() -> String? {
return self.stringByRemovingPercentEncoding // stringByReplacingPercentEscapesUsingEncoding
is deprecated
}
// URL Encode
func URLEncode() -> String? {
return self.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet(charactersInString: "!*'\"();:@&=+$,/?%#[]% ").invertedSet) // `CFURLCreateStringByAddingPercentEscapes` is deprecated
}
}
URLDecode
url.absoluteString.stringByRemovingPercentEncoding