CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.

GenericJSONType 1.0.0-alpha.2

GenericJSONType 1.0.0-alpha.2

Maintained by Linus Unnebäck.



GenericJSONType 1.0.0-alpha.2

  • By
  • Linus Unnebäck

Swift Generic JSON Type

This package provides a simple container for any JSON-data, that conforms to the Codable protocol.

Use this when you want to send the result of a function returning JSON-data as a Decodable, to another function accepting JSON-data as an Encodable; e.g. if you want to send the result of Marionette's evaluate to a JSBridge function.

Installation

SwiftPM

dependencies: [
    .package(url: "https://github.com/LinusU/GenericJSONType", from: "1.0.0"),
]

Carthage

github "LinusU/GenericJSONType" ~> 1.0.0

Usage

import GenericJSONType

let myJSONString = " ~~ any valid JSON string here ~~ ".data(using: .utf8)!

let decoder = JSONDecoder()
let decoded = try decoder.decode(JSON.self, from: myJSONString)

// `decoded` is now a structure representing the JSON data

let encoder = JSONEncoder()
let encoded = try encoder.encode(decoded)

// `encoded` is now a JSON representation of the data we started out with

Hacking

The Xcode project is generated automatically from project.yml using XcodeGen. It's only checked in because Carthage needs it, do not edit it manually.

$ mint run yonaskolb/xcodegen
💾  Saved project to GenericJSONType.xcodeproj