Skip to content

A set of helper functions for Swift Codable objects.

Notifications You must be signed in to change notification settings

ultim8p/CodableUtils

Repository files navigation

CodableUtils

A set of helper functions of any Codable object.

Features:

  • 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())

About

A set of helper functions for Swift Codable objects.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages