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)
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)
let dict: [String: Any] = ["id": 1, "eventName": "Christmas", "price": 10]
let decoder = DictionaryDecoder()
let event = try decoder.decode(Event.self, from: dict))
SwiftDictionaryCoding is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SwiftDictionaryCoding'
ashleymills, ashleymills@mac.com
SwiftDictionaryCoding is available under the MIT license. See the LICENSE file for more info.