URLQueryItemsCoder is a library for encoding an Encodable to [URLQueryItem].
The query items order is guaranteed.
struct Property: Encodable {
let a = 1
let b = [2, 3]
let c = C()
struct C: Encodable {
let a = 4
}
}
var urlComponents = URLComponents(string: "http://example.com")
urlComponents?.queryItems = try! URLQueryItemsEncoder().encode(Property())
print(urlComponents?.url?.absoluteString ?? "") // http://example.com?a=1&b%5B0%5D=2&b%5B1%5D=3&c%5Ba%5D=4 => a=1&b[0]=2&b[1]=3&c[a]=4
SwiftPM (Recommended)
- On Xcode, click
File
>Swift Packages
>Add Package Dependency...
- Input
https://github.com/malt03/URLQueryItemsCoder.git