CodableMapper is a framework written in Swift that makes it easy for you to convert your decodable model objects (classes and structs) from JSON. Inspired by ObjectMapper.
- Mapping JSON to decodable objects
- Nested Objects
- Custom transformations during mapping
- Struct support
basic and transform
{
"id": 100,
"date": "2015/03/04 12:34:56 +09:00"
}
struct Content: Decodable {
var id: Int = 0
var date: Date?
public init(from decoder: Decoder) throws {
id <- decoder["id"]
date <- (decoder["date"], DateTransform())
}
}
let content = Content(JSONString: json)!
nested json to flat.
{
"user": {
"id": 100
}
}
struct User: Decodable {
var id: Int = 0
public init(from decoder: Decoder) throws {
id <- decoder["user.id"]
}
}
look to tests.
Swift 4.0
CodableMapper is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'CodableMapper'
carthage
github 'noppefoxwolf/CodableMapper'
Tomoya Hirano, noppelabs@gmail.com
CodableMapper is available under the MIT license. See the LICENSE file for more info.