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

A static library that offers a builder pattern for URLComponents to simplify setting query parameters

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

Install

Cocoa Pods

Requires Cocoapods 1.5.0 or above.

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": "Stark",
    "password": "%&34",
    "isSuperhero": true,
    "weightKg": 75.8,
    "phones": ["mobile": "123456789",
               "office": "123987456"],
    "belongings": ["cars": ["1932 Ford Flathead Roadster",
                            "1967 Shelby Cobra",
                            "Saleen S7"], "motorcycles": ["zero eng type6"]]]

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

print(urlComponents.url!.absoluteString)

Output:
http://superherobuilder.com/buildSuit/?belongings[cars][0]=1932 Ford Flathead Roadster&belongings[cars][1]=1967 Shelby Cobra&belongings[cars][2]=Saleen S7&belongings[motorcycles][0]=zero eng type6&isSuperhero=1&name=Tony&password=%&34&phones[mobile]=123456789&phones[office]=123987456&username=Stark&weightKg=75.8

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.1.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.1.0"
    },
    "source_files": [
        "URLComponentsBuilder",
        "URLComponentsBuilder/**/*.{h,m}"
    ],
    "frameworks": "Foundation"
}

Pin It on Pinterest

Share This