美文网首页
Swift URL指定字符encoding

Swift URL指定字符encoding

作者: 艾欧尼亚 | 来源:发表于2020-05-22 11:08 被阅读0次
    1.指定支付encoding
    ["/","=","?","&"].forEach({ (char) in
        let custom = CharacterSet(charactersIn: char).inverted
        lastPath = lastPath.addingPercentEncoding(withAllowedCharacters: custom) ?? ""
    })
    
    2.指定字符不被encoding
    var charSet = CharacterSet.urlQueryAllowed
    ["#"].forEach({ (char) in
        charSet.insert(charactersIn: char)
    })
    url = url.addingPercentEncoding(withAllowedCharacters: charSet)!
    

    相关文章

      网友评论

          本文标题:Swift URL指定字符encoding

          本文链接:https://www.haomeiwen.com/subject/vmzfahtx.html