如何将其转换为当前的Swift语法。我很难过。
extension String {
var escaped: String {
return CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,self as CFString!,"[]." as CFString!,":/?&=;+!#$()@',*" as CFString!,CFStringConvertNSStringEncodingToEncoding(String.Encoding.utf8.rawValue)) as String
}
}
答案 0 :(得分:0)
简单地:
var escaped: String {
let allowedCharacters = CharacterSet(charactersIn: ":/?&=;+!#$()@',*")
return addingPercentEncoding(withAllowedCharacters: allowedCharacters)!
}