Latest 0.2.0
Homepage https://github.com/norio-nomura/ObjectEncoder
License MIT
Platforms osx 10.10, ios 8.0, tvos 9.0, watchos 2.0

ObjectEncoder for Swift

MIT License
CircleCI
codecov

SE-0167 Swift Encoders implementation using [String: Any], [Any] or Any as payload.

Usage

import Foundation
import ObjectEncoder

// single value
let string = "Hello, ObjectEncoder"
let encodedString = try ObjectEncoder().encode(string)
(encodedString as AnyObject).isEqual(to: string) // true
let decodedString = try ObjectDecoder().decode(String.self, from: encodedString)

// dictionary
struct S: Codable { let p1: String }
let s = S(p1: "string")
guard let encodedS = try ObjectEncoder().encode(s) as? [String: Any] else { fatalError() }
encodedS["p1"] // "string"
let decodedS = try ObjectDecoder().decode(S.self, from: encodedS)
decodedS.p1 // "string"

// array
let array: [S] = [s, s]
guard let encoded = try ObjectEncoder().encode(array) as? [[String: Any]] else { fatalError() }
encoded[0]["p1"] // "string"
let decoded = try ObjectDecoder().decode([S].self, from: encoded)
decoded[0].p1   // "string"

Requirements

  • Swift 4.0+ on Darwin, Swift 4.0.2+ on swift-corelibs-foundation

Author

Norio Nomura

License

ObjectEncoder is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "ObjectEncoder",
    "version": "0.2.0",
    "summary": "Swift Encoders implementation using `[String: Any]`, `[Any]` or `Any` as payload.",
    "description": "SE-0167 Swift Encoders implementation using [String: Any], [Any] or Any as payload.",
    "homepage": "https://github.com/norio-nomura/ObjectEncoder",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": "Norio Nomura",
    "source": {
        "git": "https://github.com/norio-nomura/ObjectEncoder.git",
        "tag": "0.2.0"
    },
    "source_files": "Sources/ObjectEncoder/*.swift",
    "platforms": {
        "osx": "10.10",
        "ios": "8.0",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "cocoapods_version": ">= 1.4.0",
    "swift_version": "4.0"
}

Pin It on Pinterest

Share This