ObjectMapper Template Information¶ ↑
| Name | Description | | ——— | —————– | | Folder name | templates/object-mapper | | Invocation example | gyro -m <model> -t object-mapper …
| | Language | Swift 3 |
This template is useful if you use ObjectMapper to handle the JSON parsing of your model objects. It generates an ObjectMapper
extension for each object of your data model.
Note: When using this template to handle your JSON parsing for Swift, you'll have to use the swift3-variant
template (instead of using the swift3
template) to generate your main code for Realm Object classes (as it generates var
and optional properties which are needed by ObjectMapper
)
Generated Code¶ ↑
ShopMapper.swift
:
/* DO NOT EDIT | Generated by gyro */ import ObjectMapper extension Shop: Mappable { // MARK: Initializers convenience init?(map: Map) { self.init() } // MARK: Mappable func mapping(map: Map) { // MARK: Attributes self.attrDate <- (map["attrDate"], ISO8601DateTransform()) self.attrDateCustom <- (map["attrDateCustom"], CustomDateTransformer()) self.attrDecimal <- (map["attrDecimal"], MPDecimalTransformer()) self.attrDouble <- map["attrDouble"] self.attrFloat <- (map["attrFloat"], MPDecimalTransformer()) self.attrInteger16 <- (map["attrInteger16"], MPIntegerTransformer()) self.attrInteger32 <- map["attrInteger32"] self.attrInteger64 <- (map["attrInteger64"], MPIntegerTransformer()) } }