Skip to content

EncodingError for Codable protocols

License

Notifications You must be signed in to change notification settings

swiftstack/codable

Repository files navigation

Codable

Helps you to throw an error on container request step, which is not allowed by the current Encodable design.

Package.swift

.package(url: "https://github.com/swiftstack/codable.git", .branch("dev"))

Usage

struct Encoder: Swift.Encoder {
    func container<Key: CodingKey>(keyedBy type: Key.Type) -> KeyedEncodingContainer<Key> {
        do {
            // try
        } catch {
            return KeyedEncodingContainer(KeyedEncodingError(error))
        }
    }

    func unkeyedContainer() -> UnkeyedEncodingContainer {
        do {
            // try
        } catch {
            return EncodingError(error)
        }
    }

    func singleValueContainer() -> SingleValueEncodingContainer {
        do {
            // try
        } catch {
            return EncodingError(error)
        }
    }
}

Releases

No releases published

Packages

No packages published