malt03 / URLQueryItemsCoder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

URLQueryItemsCoder Build Status SwiftPM compatible License

URLQueryItemsCoder is a library for encoding an Encodable to [URLQueryItem].

Usage

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

Installation

SwiftPM (Recommended)

  • On Xcode, click File > Swift Packages > Add Package Dependency...
  • Input https://github.com/malt03/URLQueryItemsCoder.git

About

License:MIT License


Languages

Language:Swift 100.0%