Latest 1.0
Homepage https://github.com/gmarm/DecodeFailable
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

DecodeFailable provides a custom Decodable collection that decoding for individual elements can fail silently for.
Thus, malformed or unknown elements in a JSON array won’t result in a failure of the entire decoding.

It also makes it easy to log or add custom handling of decoding errors for those elements.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 8.0+
  • Swift 4.2+

Installation

CocoaPods

DecodeFailable is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'DecodeFailable'

Manually

If you prefer not to use CocoaPods, you can integrate DecodeFailable into your project manually.

Usage

Using DecodeFailable is very simple. All you need to implement is init(from decoder: Decoder) and use DecodeFailableArray for your array decoding.

import DecodeFailable

struct GetPeopleResponse: Codable {
    private enum CodingKeys: String, CodingKey {
        case people
    }
    let people: [Person]

    public init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)

        self.people = try container.decode(DecodeFailableArray<Person>.self, forKey: .people).elements
    }
}

struct Person: Codable {
    let id: String
    let firstName: String
    let lastName: String
}

Author

George Marmaridis

License

DecodeFailable is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "DecodeFailable",
    "version": "1.0",
    "summary": "Allows decoding to fail for individual elements in arrays using Codable",
    "description": "DecodeFailable provides a custom `Decodable` collection that decoding for individual elements can fail silently for.nThus, malformed or unknown elements in a JSON array won't result in a failure of the entire decoding. It also makes itneasy to log or add custom handling of decoding errors for those elements.",
    "homepage": "https://github.com/gmarm/DecodeFailable",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "George Marmaridis": "[email protected]"
    },
    "source": {
        "git": "https://github.com/gmarm/DecodeFailable.git",
        "tag": "1.0"
    },
    "social_media_url": "https://twitter.com/gmarmas",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "DecodeFailable/Classes/**/*",
    "swift_version": "4.2"
}

Pin It on Pinterest

Share This