Convert dictionary to query string in swift?

前端 未结 11 776
走了就别回头了
走了就别回头了 2021-01-04 04:37

I have a dictionary as [String:Any].Now i want to convert this dictionary keys & value as key=value&key=value.I have created below extensio

11条回答
  •  被撕碎了的回忆
    2021-01-04 05:17

    Try this :

    func queryItems(dictionary: [String:Any]) -> String {
            var components = URLComponents()
            print(components.url!)
            components.queryItems = dictionary.map {
                URLQueryItem(name: $0, value: $1)
            }
           return (components.url?.absoluteString)!
        }
    

提交回复
热议问题