Latest 1.0.0
Homepage https://github.com/ga083/URLComponentsBuilder
License MIT
Platforms ios 10.0
Frameworks Foundation
Authors

A builder pattern for URLComponents to simplify setting query parameters

Translates a ‘Dictionary’ to ‘URLQueryItem(s)’. Simplifies setting query parameters, specifically avoiding the cumbersome task of representing arrays and dictionaries in an URL query.

Install

Cocoa Pods

target '<you project target>' do
    pod 'URLComponentsBuilder'
end

Or just copy this file into your project

URLComponentsBuilder.swift

Usage example

let query: [String: Any] = [
    "name": "Tony",
    "username": "Stärk",
    "password": "%&34",
    "isSuperhero": true,
    "weightKg": 75.8,
    "phones": ["mobile": "123456789", "office": "123987456"]]

var urlComponents = URLComponentsBuilder()
        .setScheme("http")
        .setHost("urlbuilder.com")
        .setPath("/buildSuit/")
        .addQuery(items: query)
        .build()

print(urlComponents.url!.absoluteString)

Output:

http://urlbuilder.com/buildSuit/?isSuperhero=1&name=Tony&password=%25%2634&phones%5Bmobile%5D=123456789&phones%5Boffice%5D=123987456&username=St%C3%A4rk&weightKg=75.

License

This project is licensed under the MIT License – see the LICENSE file for details

Latest podspec

{
    "name": "URLComponentsBuilder",
    "platforms": {
        "ios": "10.0"
    },
    "swift_version": "4.2",
    "version": "1.0.0",
    "summary": "A builder pattern for URLComponents to simplify setting query parameters.",
    "description": "Translates a 'Dictionary' to 'URLQueryItem(s)'. Simplifies setting query parameters, specifically avoiding the cumbersome task of representing arrays and dictionaries in an URL query.",
    "homepage": "https://github.com/ga083/URLComponentsBuilder",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Alexander Solis": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ga083/URLComponentsBuilder.git",
        "tag": "1.0.0"
    },
    "source_files": [
        "URLComponentsBuilder",
        "URLComponentsBuilder/**/*.{h,m}"
    ],
    "frameworks": "Foundation"
}

Pin It on Pinterest

Share This