How can I build a URL with query parameters containing multiple values for the same key in Swift?

后端 未结 7 1135
一生所求
一生所求 2020-12-08 18:35

I am using AFNetworking in my iOS app and for all the GET requests it makes, I build the url from a base URL and than add parameters using NSDictionary Key-Value pairs.

7条回答
  •  一生所求
    2020-12-08 19:13

    In Swift Forming URL with multiple params

    func rateConversionURL(with array: [String]) -> URL? {
                var components = URLComponents()
                components.scheme = "https"
                components.host = "example.com"
                components.path = "/hello/"
                components.queryItems = array.map { URLQueryItem(name: "value", value: $0)}
    
            return components.url
        }
    

提交回复
热议问题