A set of helper functions of any Codable object.
- Get class name from a Codable object:
let nameString = MyModel.className
print(nameString) // output: MyModel
- Convert a Codable object into a dictionary:
let obj = MyModel(name: "John", age: 24)
let objDict = obj.toDictionary()
// Optionally use a custom JSONEncoder
let objDict = obj.toDictionary(encoder: CustomJSONEncoder())
- Convert a dictionary into a Codable object:
let objDict = ["name": "John", age: 24]
let obj = objDict.toModel(MyModel.self)
//Optionally use a custom JSONDecoder
let obj = objDict.toModel(MyModel.self, decoder: CustomJSONDecoder())