Swiftpack.co - makoni/parsable as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by makoni.
makoni/parsable 1.0.3
Syntax sugar that makes JSON decoding more elegant.
⭐️ 0
🕓 5 weeks ago
.package(url: "https://github.com/makoni/parsable.git", from: "1.0.3")


Syntax sugar that makes JSON decoding more elegant.

Swift 5 Swift Package Manager Build and test


Swift Package Manager

Add to the dependencies value of your Package.swift.

Swift 5

dependencies: [
	.package(url: "https://github.com/makoni/parsable.git", from: "1.0.0"),


Example struct should conform to Codable and Parseable protocols:

#import Parsable

// Example struct that conforms to Codable protocol
struct SampleErrorModel: Codable {
	var error: String?
	var code: Int?

// Parseable protocol conformance. That's it.
extension SampleErrorModel: Parseable {
	typealias ParseableType = Self

Encode model -> JSON:

let sampleModel = SampleErrorModel(error: "error message text", code: 404)
let jsonData = SampleErrorModel.encode(fromEncodable: sampleModel)
// or
let jsonData = SampleErrorModel.encode(fromEncodable: error, withDateEncodingStrategy: .millisecondsSince1970)

Decode JSON -> model:

let decodedModel = SampleErrorModel.decodeFromData(data: jsonData)
// or
let decodedModel = SampleErrorModel.decodeFromData(data: jsonData, withDateDecodingStrategy: .millisecondsSince1970)


Stars: 0
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics