SafeDecoder - a swift package that set defaults when Codable fails to decode a field

Overview

SafeDecoder

SafeDecoder is a swift package that set defaults when Codable fails to decode a field. SafeDecoder supports configurable default values, See SafeDecoder.Configuration.

Installation

Swift Package Manager

Swift Package Manager is Apple's decentralized dependency manager to integrate libraries to your Swift projects. It is now fully integrated with Xcode 11

To integrate SafeDecoder into your project using SPM, specify it in your Package.swift file:

let package = Package(
    
    dependencies: [
        .package(url: "[email protected]:GodL/SafeDecoder.git", from: "1.0.0"),
    ],
    targets: [
        .target(name: "YourTarget", dependencies: ["SafeDecoder", ])
        
    ]
)

Usage

normal

let model: Data1 = try SafeDecoder().decode(Data1.self, from: try encode(testData))

custom

struct CustomConfiguration: SafeConfigurationType {
    static var configuration: SafeDecoder.Configuration {
        var configuration: SafeDecoder.Configuration = .default
        configuration.register([Data1.Epidemic].self, value: [.init(title: "aaa", num: 20, routeUri: "test://url")])
        return configuration
    }
}
let model: Data1 = try SafeDecoder().decode(Data1.self, CustomConfiguration.self, from: try encode(testData))

Author

GodL, [email protected]. Github GodL

I am happy to answer any questions you may have. Just create a new issue.

You might also like...
A corresponding package to RxKotlin Plus, but for Swift and iOS

A corresponding package to RxKotlin Plus, but for Swift and iOS

An IPFS client/api Swift Package, with the ability to add and pin any data on iOS/iPadOS/macOS

An IPFS client/api Swift Package, with the ability to add and pin any data on iOS/iPadOS/macOS. Originally bundled with GraniteUI, pulled out for independant use by any party.

A Swift package that provides convenient Lorem Ipsum text, images, colors and other placeholders for rapidly prototyping, building and testing your iOS applications.
A Swift package that provides convenient Lorem Ipsum text, images, colors and other placeholders for rapidly prototyping, building and testing your iOS applications.

Lorem Introducing Lorem, a placeholder generator library for iOS to help you rapidly prototype, build and test your iOS applications. By leveraging Sw

A macOS application for accessing the output of the SimpleAnalytics package on the desktop.
A macOS application for accessing the output of the SimpleAnalytics package on the desktop.

The SimpleAnalytics package allows you to collect data user interaction analytic data in iOS and macOS applications. This SimpleAnalytics Reader app project allows you to more easily make sense of that collected data by displaying it on your Mac.

Flutter package for detecting NSFW images and videos using native implementation

Flutter NSFW 1- Download, tflite modle and put it in assets folder 2 - Add the path of the tfliet to pubspec.yaml 3 - Read the file using path_provide

React Native package for interacting with HomeKit devices

React Native package for interacting with HomeKit devices

A simple protocol package that does nothing

HasResult A simple protocol package that does nothing. The HasResult protocol has a simple result property and a ResultType associated type. This is m

Package that extends Combine with some useful APIs

CombineExpanded Package that extends Combine with some useful APIs. New API: then shareReplay Future.deferred then Wait for completion of self, then f

FlutterNativeDragAndDrop - A package that allows you to add native drag and drop support into your flutter app
FlutterNativeDragAndDrop - A package that allows you to add native drag and drop support into your flutter app

native_drag_n_drop A package that allows you to add native drag and drop support

Owner
GodL
a developer
GodL
A Collection of PropertyWrappers to make custom Serialization of Swift Codable Types easy

CodableWrappers Simplified Serialization with Property Wrappers Move your Codable and (En/De)coder customization to annotations! struct YourType: Coda

null 393 Jan 5, 2023
Powerful property wrapper to back codable properties.

BackedCodable Powerful property wrapper to back codable properties. Why Swift's Codable is a great language feature but easily becomes verbose and req

Jérôme Alves 472 Dec 18, 2022
Find the union of a set of axis-aligned rectangles

RectangleContour My main product is a library named RectangleContour which contains one Swift module also named RectangleContour. The library implemen

Rob Mayoff 18 Dec 21, 2022
Puma - A set of build utilities to automate mobile application development and deployment

Puma → https://github.com/onmyway133/Swiftlane Puma is a set of build utilities

Puma Swift 5 Oct 8, 2022
Set `Open using Rosetta` option on Xcode easily

xcode-arch A utility to switch running architecture of Xcode on M1 mac. Motivation Currently, there is no way to toggle Open using Rosetta option othe

Takuhiro Muta 7 Aug 8, 2022
A novel way to set attributes to the Font in SwiftUI.

A novel way to set attributes to the Font in SwiftUI.

Riiid 6 Oct 13, 2022
A Swift package for encoding and decoding Swift Symbol Graph files.

SymbolKit The specification and reference model for the Symbol Graph File Format. A Symbol Graph models a module, also known in various programming la

Apple 141 Dec 9, 2022
WebDomHandling - A Swift Package for handling JavaScript code between WebKit and Swift implemented by WebKit

WebDomHandling A Swift Package for handling JavaScript code between WebKit and S

null 0 Jan 23, 2022
This is a Swift Package bundling different Train APIs into one simple Swift interface.

This is a Swift Package bundling different Train APIs into one simple Swift interface.

ICE Buddy 8 Jul 5, 2022
This repository hosts the PushwooshGeozones iOS SDK as an XCFramework based Swift Package.

This repository hosts the PushwooshGeozones iOS SDK as an XCFramework based Swift Package. Use this repository's Swift Package in Xcode 12+

Pushwoosh 2 Nov 23, 2021