[go: up one dir, main page]

Skip to content

Decode / encode instances of a Decodable/Encodable object to / from dictionaries -

License

Notifications You must be signed in to change notification settings

ashleymills/SwiftDictionaryCoding

Repository files navigation

SwiftDictionaryCoding

CI Status Version License Platform

This library allows you to use a encode/decode Swift objects that conform to Codable protocols to and from Dictionaries in the same way you'd use a JSONEncoder/Decoder to convert to JSON. They use the same encoding and decoding strategies as their JSON counterparts (because they wrap the JSON equivalents)

Encoding

struct Event: Codable {
    let id: Int
    let location: String?
    let price: Float?
}

let event = Event(id: 1, eventName: "Christmas", location: nil, price: 10)
let encoder = DictionaryEncoder()
let dict = try encoder.encode(event) 

Decoding

let dict: [String: Any] = ["id": 1, "eventName": "Christmas", "price": 10]        
let decoder = DictionaryDecoder()
let event = try decoder.decode(Event.self, from: dict))

Installation

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

pod 'SwiftDictionaryCoding'

Author

ashleymills, ashleymills@mac.com

License

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

About

Decode / encode instances of a Decodable/Encodable object to / from dictionaries -

Resources

License

Stars

Watchers

Forks

Packages

No packages published