Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fromkk/urlquerybuilder
URLQueryBuilder is able to build query string for URL from Dictionary
https://github.com/fromkk/urlquerybuilder
carthage ios macos swift swift-3 swift-library tvos watchos
Last synced: about 2 months ago
JSON representation
URLQueryBuilder is able to build query string for URL from Dictionary
- Host: GitHub
- URL: https://github.com/fromkk/urlquerybuilder
- Owner: fromkk
- License: mit
- Created: 2017-08-02T06:04:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-02T06:53:45.000Z (over 7 years ago)
- Last Synced: 2024-10-28T01:15:33.158Z (3 months ago)
- Topics: carthage, ios, macos, swift, swift-3, swift-library, tvos, watchos
- Language: Swift
- Homepage:
- Size: 18.6 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# URLQueryBuilder with Swift
`URLQueryBuilder` is able to build query string for URL from Dictionary type.
---
## Requirements
- Swift 3.0 or later
---
## Installation
### Carthage
- Insert `github "fromkk/URLQueryBuilder"` to your `Cartfile` .
- Run `carthage update`
- Link your app with `URLQueryBuilder.framework` in `Carthage/Build`---
## Usage
Query string from simple dictionary.
```swift
import URLQueryBuilderlet someDictionary: [String: Any] = ["key1": "hello", "key2": "world"]
let queryBuilder: URLQueryBuilder = URLQueryBuilder(dictionary: someDictionary)
let queryString: String = queryBuilder.build() //key1=hello&key2=world
```Query string from multibyte characters.
```swift
let someDictionary: [String: Any] = ["key": "マルチバイト👨👩👧👦"]
let queryString: String = URLQueryBuilder(dictionary: someDictionary).build(with: [.urlEncoding]) //key=%E3%83%9E%E3%83%AB%E3%83%81%E3%83%90%E3%82%A4%E3%83%88%F0%9F%91%A8%E2%80%8D%F0%9F%91%A9%E2%80%8D%F0%9F%91%A7%E2%80%8D%F0%9F%91%A6
```Query string from deep hierarchy dictionary.
```swift
let deepDictionary: [String: Any] = ["key": ["subkey": "subvalue"]]
let queryString: String = URLQueryBuilder(dictionary: deepDictionary).build() //key[subkey]=subvalue```
Query string from array.
```swift
let arrayDictionary: [String: Any] = ["array": ["hello", "world"]]
let queryString: String = URLQueryBuilder(dictionary: arrayDictionary).build() //array[0]=hello&array[1]=world
```