swifturlcomponents

How can I make URLQueryItem with large bracket ([])?


I need to make a URL with query parameter with large bracket. this is the example.

https://samlpe.com/detail?item_code[]=smtwGBArkp3ByfrLK3KfxdoX

I trying to use URLComponents and URLQueryItem. but URLQueryItem don't take array (["code"] in below) as a value.

var urlComponents = URLComponents(url: URL(string: "https://samlpe.com/detail")!,
                                                        resolvingAgainstBaseURL: false)
        urlComponents.queryItems = [URLQueryItem(name: "item_code", value: ["code"])]

Does anybody hove idea for that?


Solution

  • The [] has no special meaning. This is just:

    URLQueryItem(name: "item_code[]", value: "smtwGBArkp3ByfrLK3KfxdoX")