Swiftpack.co -  osrufung/SafeCodable as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Swift Codable extensions
.package(url: "https://github.com/osrufung/SafeCodable.git", from: "v0.0.2")



Collection of Decodable extensions to help you when JSON responses safety is not guaranteed


Safe base/alternative types

struct Book: Decodable {
    let year: Safe<Int, String>
    let name: String

let rawJson = """
        "year": 1951,
        "name": "Foundation"
        "year": "1984",
        "name": "Neuromancer"
let decoder = JSONDecoder()
let books = try decoder.decode([Book].self, from: rawJson.data(using: .utf8)!)

print(books.first?.year.value) //Optional(1951)
print(books.last?.year.value) //Optional(1984)

Safe Date multi-format types

Some responses contains multiple types of Date formatting (iOS8601 with seconds, milliseconds or single dates)

let rawDates = """
    { "value" : "2015-08-29T11:22:09Z"},
    { "value" : "2015-08-29T11:22:09.129Z"},
    { "value" : "2020-11-27"},
    { "value" : "2019-08-03 23:59:59"}

""".data(using: .utf8)
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601(extended: true)
struct DateContainer: Decodable {
    let value: Date?

let dates = try? decoder.decode([DateContainer].self, from: rawDates!)
XCTAssertEqual(dates?.count, 4)


Stars: 1
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

27 weeks ago

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