A Swift Encoder for encoding any Encodable value into an array of URLQueryItem.

Overview

URLQueryItemEncoder

Platform Swift support CocoaPods Compatible Carthage compatible Swift Package Manager compatible Twitter

A Swift Encoder for encoding any Encodable value into an array of URLQueryItem. As part of the SE-0166, Swift has a foundation for any type to define how its value should be archived. This encoder allows you to encode those value into an array of URLQueryItem which represent that value in one command.

struct Language {
  let name: String
  let age: Int
}

let person = Language(name: "Swift", age: 4)
let encoder = URLQueryItemEncoder()
let items = try encoder.encode(person)
// items == [URLQueryItem(name: "name", value: "Swift"), URLQueryItem(name: "age", value: "4")]

Requirements

  • iOS 8+
  • macOS 10.10+
  • Swift 4.0+

Installation

Manually

This project comes with built in URLQueryItemEncoder framework target. You can drag URLQueryItemEncoder.xcproj file into your project, add URLQueryItemEncoder framework target as a target dependency and link/embed that framework. and Voila!!!

import URLQueryItemEncoder

Or you can copy the URLQueryItemEncoder.swift file into your project.

CocoaPods

Add the following to your Podfile

pod 'URLQueryItemEncoder'
use_frameworks!

Carthage

Add the following to your Cartfile

github "pitiphong-p/URLQueryItemEncoder"

Swift Package Manager

You can use Swift Package Manager and specify dependency in Package.swift by adding this:

dependencies: [
    .Package(url: "https://github.com/pitiphong-p/URLQueryItemEncoder.git", majorVersion: 0)
]

Usage

The URLQueryItemEncoder has a simple and familiar API. It has only 1 method for performing the encoding and 1 strategy for choosing how to encode the Array Index key.

let encoder = URLQueryItemEncoder()
let items = try encoder.encode(person)

Contact

Pitiphong Phongpattranont

License

URLQueryItemEncoder is released under an MIT License.
Copyright © 2017-present Pitiphong Phongpattranont.

You might also like...
Merges a given number of PDF files into one file using the PDFKit framework

Titanium iOS PDF Merge Merges a given number of PDF files into one file using the PDFKit framework Requirements iOS 11+ Titanium SDK 9+ API's Methods

Read iOS 15 privacy insight '.ndjson' file into your human brain.
Read iOS 15 privacy insight '.ndjson' file into your human brain.

Insight Read iOS 15 privacy insight '.ndjson' file into your human brain. Written in SwiftUI. Feature Compile records into app summary Relink app info

Passing data from a couple of screen into a Model
Passing data from a couple of screen into a Model

Passing-Data Passing data from a couple of screen into a Model Introduction Hi, this video is just a representation project from this Video by Essenti

Decode a string encoded in Base64 into an https link and launch it in Google Chrome

Decode a string encoded in Base64 into an https link and launch it in Google Chr

HxSTLParser is a basic STL parser capable of loading STL files into an SCNNode

HxSTLParser HxSTLParser is a basic STL parser capable of loading STL files into an SCNNode. Installing Via Carthage Just add it to your Cartfile githu

Functional data types and functions for any project

Swiftx Swiftx is a Swift library containing functional abstractions and extensions to the Swift Standard Library. Swiftx is a smaller and simpler way

Measure the power output from a car or any moving vehicle from GPS data and weight
Measure the power output from a car or any moving vehicle from GPS data and weight

GPSDyno Measure the power output from a car or any moving vehicle from weight and GPS data of your iOS device. This is just a example project and shou

BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Comments
  • Segfault on swift 4.1

    Segfault on swift 4.1

    Hi 👋,

    Thanks for opening sourcing this. Sadly It doesn't compile with swift 4.1 (at least for me). I've tried commenting out the code to try to isolate the issue with no success so far. I'll update if I find a solution.

    Travis Failures on 9.1

    Assertion failed: (!ty->hasError() && "Serializing error type"), function addTypeRef, file /Users/buildnode/jenkins/workspace/oss-swift-4.1-package-osx/swift/lib/Serialization/Serialization.cpp, line 617.
    0  swift                    0x00000001060284d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
    1  swift                    0x0000000106028be6 SignalHandler(int) + 694
    2  libsystem_platform.dylib 0x00007fffa2321b3a _sigtramp + 26
    3  libsystem_platform.dylib 0x00007fafa130de10 _sigtramp + 4278108912
    4  libsystem_c.dylib        0x00007fffa21a6420 abort + 129
    5  libsystem_c.dylib        0x00007fffa216d893 basename_r + 0
    6  swift                    0x00000001039a2848 swift::serialization::Serializer::addTypeRef(swift::Type) + 408
    7  swift                    0x00000001039aa1d1 swift::serialization::Serializer::writeSubstitutions(llvm::ArrayRef<swift::Substitution>, std::__1::array<unsigned int, 256ul> const&, swift::GenericEnvironment*) + 161
    8  swift                    0x00000001039a9887 swift::serialization::Serializer::writeNormalConformance(swift::NormalProtocolConformance const*) + 2919
    9  swift                    0x00000001039b99fb swift::serialization::Serializer::writeAllDeclsAndTypes() + 2827
    10 swift                    0x00000001039baf6a swift::serialization::Serializer::writeAST(llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, bool) + 3242
    11 swift                    0x00000001039c201b swift::serialization::Serializer::writeToStream(llvm::raw_ostream&, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::SILModule const*, swift::SerializationOptions const&) + 139
    12 swift                    0x0000000103a03b73 void llvm::function_ref<void (llvm::raw_ostream&)>::callback_fn<swift::serialize(llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::SerializationOptions const&, swift::SILModule const*)::$_4>(long, llvm::raw_ostream&) + 179
    13 swift                    0x00000001039c3278 withOutputFile(swift::ASTContext&, llvm::StringRef, llvm::function_ref<void (llvm::raw_ostream&)>) + 440
    14 swift                    0x00000001039c303c swift::serialize(llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::SerializationOptions const&, swift::SILModule const*) + 220
    15 swift                    0x0000000102ae6709 std::__1::__function::__func<performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*)::$_6, std::__1::allocator<performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*)::$_6>, void ()>::operator()() + 617
    16 swift                    0x0000000103717e54 swift::SILModule::serialize() + 36
    17 swift                    0x0000000102adf2ed performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 12621
    18 swift                    0x0000000102adb1b0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3376
    19 swift                    0x0000000102a9aa63 main + 3075
    20 libdyld.dylib            0x00007fffa2112235 start + 1
    21 libdyld.dylib            0x0000000000000048 start + 1575935508
    Stack dump:
    0.	Program arguments: /Library/Developer/Toolchains/swift-4.1-RELEASE.xctoolchain/usr/bin/swift -frontend -merge-modules -emit-module /Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/Debug/URLQueryItemEncoder.build/Objects-normal/x86_64/URLQueryItemEncoder~partial.swiftmodule -parse-as-library -sil-merge-partial-modules -disable-diagnostic-passes -disable-sil-perf-optzns -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -I /Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Products/Debug -F /Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Products/Debug -application-extension -enable-testing -g -import-underlying-module -module-cache-path /Users/iainsmith/Library/Developer/Xcode/DerivedData/ModuleCache -swift-version 4 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -report-errors-to-debugger -Xcc -I/Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/Debug/URLQueryItemEncoder.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/Debug/URLQueryItemEncoder.build/URLQueryItemEncoder-generated-files.hmap -Xcc -I/Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/Debug/URLQueryItemEncoder.build/URLQueryItemEncoder-own-target-headers.hmap -Xcc -I/Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/Debug/URLQueryItemEncoder.build/URLQueryItemEncoder-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/Debug/URLQueryItemEncoder.build/URLQueryItemEncoder-project-headers.hmap -Xcc -I/Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Products/Debug/include -Xcc -I/Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/Debug/URLQueryItemEncoder.build/DerivedSources/x86_64 -Xcc -I/Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/Debug/URLQueryItemEncoder.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -ivfsoverlay -Xcc /Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/Debug/URLQueryItemEncoder.build/unextended-module-overlay.yaml -Xcc -working-directory/Users/iainsmith/Code/TravisClient/Packages/URLQueryItemEncoder -emit-module-doc-path /Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/Debug/URLQueryItemEncoder.build/Objects-normal/x86_64/URLQueryItemEncoder.swiftdoc -module-name URLQueryItemEncoder -emit-objc-header-path /Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/Debug/URLQueryItemEncoder.build/Objects-normal/x86_64/URLQueryItemEncoder-Swift.h -o /Users/iainsmith/Library/Developer/Xcode/DerivedData/URLQueryItemEncoder-bopdpxwfmmdflugdadetwtpslgjj/Build/Intermediates.noindex/URLQueryItemEncoder.build/Debug/URLQueryItemEncoder.build/Objects-normal/x86_64/URLQueryItemEncoder.swiftmodule 
    1.	While serializing type 'τ_1_0'
    
    opened by iainsmith 2
  • Remove spaces and change to trailing closure

    Remove spaces and change to trailing closure

    Changes in this pull request

    • remove some extra spaces
    • ~~change updateAccumulatingResult parameter for reduce method to trailing closure style.~~

    • [x] All tests pass.
    opened by ambas 2
  • error: cannot convert value of type 'Int' to expected element type 'SwiftVersion'

    error: cannot convert value of type 'Int' to expected element type 'SwiftVersion'

    I'm trying to use SPM to integrate URLQueryItemEncoder. But there is an error occurred. When I run $ swift build. It said:

    Fetching https://github.com/pitiphong-p/URLQueryItemEncoder.git
    https://github.com/pitiphong-p/URLQueryItemEncoder.git @ 0.2.3: error: manifest parse error(s):
    /var/folders/3q/8y8vld8540d1xbsm5l69tkjh0000gp/T/TemporaryFile.s7skzt.swift:24:29: error: cannot convert value of type 'Int' to expected element type 'SwiftVersion'
        swiftLanguageVersions: [5]
    

    Here is my environment:

    $ swift --version
    Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
    Target: x86_64-apple-darwin19.0.0
    
    opened by ihomway 1
Owner
Pitiphong Phongpattranont
A long time iOS developer who's also interested in Programming, Apple and, design. Opinions are my own
Pitiphong Phongpattranont
Easy CBOR encoding and decoding for iOS, macOS, tvOS and watchOS.

CBORCoding CBORCoding is a lightweight framework containing a coder pair for encoding and decoding Codable conforming types to and from CBOR document

Joe Newton 23 Nov 8, 2022
Array diffs as collection view wants it - now in Swift ✨

Doppelganger-Swift Inspired by Doppelganger written in Swift Features Removes confusion from users when data changes Animates moving, inserting and de

Szymon Maślanka 9 Jul 9, 2019
StoredIn is a simple property wrapper library to store any value in anywhere

StoredIn StoredIn is a simple property wrapper library to store any value in anywhere. Installation Please use the Swift Package Manager. dependencies

Henrique Sasaki Yuya 2 Jul 4, 2022
A Swift property wrapper which stores the previous value

swift-with-previous A Swift property wrapper which stores the previous value. The previous value can be get by the projected value $propertyName. impo

IKEDA Sho 3 Feb 22, 2022
A collection of useful result builders for Swift and Foundation value types

Swift Builders A collection of useful result builders for Swift and Foundation value types. Motivation Arrays, dictionaries, and other collection-base

David Roman 3 Oct 14, 2022
AnalyticsKit for Swift is designed to combine various analytical services into one simple tool.

?? AnalyticsKit AnalyticsKit for Swift is designed to combine various analytical services into one simple tool. To send information about a custom eve

Broniboy 6 Jan 14, 2022
Parse iOS mobile provisioning files into Swift models

SwiftyProvisioningProfile This library provides a way to decode a .mobileprovision file into a Swift model. Installation The recommended installation

James Sherlock 60 Nov 25, 2022
Project shows how to unit test asynchronous API calls in Swift using Mocking without using any 3rd party software

UnitTestingNetworkCalls-Swift Project shows how to unit test asynchronous API ca

Gary M 0 May 6, 2022
Swift For Any Measure: Simplified

AnyMeasure Swift For Any Measure: Simplified A clean, Swift interface for Foundation.Measurement Read my post about it here. Requirements: Swift 4.0+

Jason Jobe 3 Sep 25, 2022
Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Mathias Quintero 9 Sep 25, 2022