Latest 1.1.1
Homepage https://github.com/alexaubry/QuerySerialization
License MIT
Platforms ios 8.0, osx 10.9, watchos 2.0, tvos 9.0
Frameworks Foundation
Authors

Swift 4.0
License
CocoaPods
Carthage compatible
Build Status

QuerySerialization is a Swift library that allows you to encode dictionaries into query strings, and to decode query strings into dictionaries. It also supports automatic percent encoding/decoding.

📚 Documentation

Platforms

  • iOS 8.0+
  • macOS 10.9+
  • tvOS 9.0+
  • watchOS 2.0+
  • Linux

Installation

QuerySerialization version vs. Swift version

Swift QuerySerialization
4.X >= 1.1.0
3.X >= 1.0.0

Swift Package Manager

Add this line to your Package.swift:

.Package(url: "https://github.com/alexaubry/QuerySerialization.git", from: "1.1.0")

CocoaPods

Add this line to your Podfile:

pod "QuerySerialization"

Carthage

Add this line to your Cartfile:

github "alexaurby/QuerySerialization"

Manually

Drag the QuerySerialization.swift file into your project.

Usage

You use the QuerySerialization class to encode or decode query strings.

Encoding

To encode a dictionary into a query string, call:

let queryElements = ["key":"value","message":"Hello world"]
let queryString = QuerySerialization.queryString(fromDictionary: queryElements)

// queryString = "key=value&message=Hello%20world"

As you may notice, percent encoding is added automatically by default. You can opt-out this feature by using this instead:

let queryElements = ["key":"value","message":"Hello world"]
let queryString = QuerySerialization.queryString(fromDictionary: queryElements, urlEncode: false)

// queryString = "key=value&message=Hello world"

Decoding

To decode a query string into a Dictionary, call:

let queryString = "key=value&message=Hello%20world"
let queryElements = QuerySerialization.decode(queryString: queryString)

// queryElements = ["key":"value","message":"Hello world"]

If a key or value contains percent encoding, it will be removed automatically. You can opt-out this feature by using this instead:

let queryString = "key=value&message=Hello%20world"
let queryElements = QuerySerialization.decode(queryString: queryString, removePercentEncoding: false)

// queryElements = ["key":"value","message":"Hello%20world"]

Author

License

QuerySerialization is available under the MIT License. See the LICENSE file for more info.

Latest podspec

{
    "name": "QuerySerialization",
    "version": "1.1.1",
    "summary": "Encode and Decode Query Strings in Swift",
    "description": "QuerySerialization allows you to encode dictionaries into query strings, and to decode query strings to dictionaries. It also supports automatic percent encoding/decoding.",
    "homepage": "https://github.com/alexaubry/QuerySerialization",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Alexis Aubry Radanovic": "[email protected]"
    },
    "social_media_url": "https://twitter.com/_alexaubry",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/alexaubry/QuerySerialization.git",
        "tag": "1.1.1"
    },
    "source_files": "Sources/**/*",
    "frameworks": "Foundation",
    "documentation_url": "https://alexaubry.github.io/QuerySerialization",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This