class BaseModel: Mappable { var man : Bool? = true
var age : Int? = 21 init() { } required init?(map: Map) { print("BaseModel初始化") } func mapping(map: Map) { man <- (map["man"],transformBool)
age <- (map["age"],transformInt) } // 转换规则 let transformInt = TransformOf<Int, String>(fromJSON: { (value: String?) -> Int? in if let value = value { return Int(value)! } return nil }, toJSON: { (value: Int?) -> String? in // transform value from Int? to String? if let value = value { return String(value) } return nil }) let transformBool = TransformOf<Bool, String>(fromJSON: { (value: String?) -> Bool? in if let value = value { return (value as NSString).boolValue } return false }, toJSON: { (value: Bool?) -> String? in if let value = value { return String(value) } return "false" })