Parse and serialize url-encoded form data with Codable support.
- This is an (En/De)coder that converts URL query item parameters to Codable.
- The original source has been modified to use the url-encoded-form created by the Vapor team through Foundation.
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
Once you have your Swift package set up, adding Alamofire as a dependency is as easy as adding it to the dependencies value of your Package.swift.
dependencies:[.package(url:"https://github.com/interactord/URLEncodedForm",.upToNextMajor(from:"1.0.0"))]It supports Codable provided by the Swift Foundation.
structMyInfo:Codable{letheight:Doubleletname:Stringletfriends:[String]letfamily:FamilystructFamily:Codable{letnames:[String]}}letme=MyInfo(
height:172.2,
name:"Scott",
friends:["tom","john","mike"],
family:.init(
names:["Father","Mother","Brother"]))do{letdata=tryURLEncodedFormEncoder().encode(me)print(String(data: data, encoding:.utf8)??"nil")letorigin="name=Scott&height=172.2&friends[]=tom&friends[]=john&friends[]=mike&family[names][]=Father&family[names][]=Mother&family[names][]=Brother"letobj=tryURLEncodedFormDecoder().decode(MyInfo.self, from: origin)print(obj)}catch{print(error)}URLEncodedForm is released under the MIT license. See LICENSE for details.