use basename for swift model property

This commit is contained in:
wing328
2016-03-18 12:02:26 +08:00
parent 431593f3cf
commit 9525d67cd8
7 changed files with 17 additions and 10 deletions

View File

@@ -177,7 +177,7 @@ class Decoders {
Decoders.addDecoder(clazz: ModelReturn.self) { (source: AnyObject) -> ModelReturn in
let sourceDictionary = source as! [NSObject:AnyObject]
let instance = ModelReturn()
instance._return = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["_return"])
instance._return = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["return"])
return instance
}
@@ -191,6 +191,7 @@ class Decoders {
let sourceDictionary = source as! [NSObject:AnyObject]
let instance = Name()
instance.name = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["name"])
instance.snakeCase = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["snake_case"])
return instance
}
@@ -239,7 +240,7 @@ class Decoders {
Decoders.addDecoder(clazz: SpecialModelName.self) { (source: AnyObject) -> SpecialModelName in
let sourceDictionary = source as! [NSObject:AnyObject]
let instance = SpecialModelName()
instance.specialPropertyName = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["specialPropertyName"])
instance.specialPropertyName = Decoders.decodeOptional(clazz: Int.self, source: sourceDictionary["$special[property.name]"])
return instance
}

View File

@@ -18,7 +18,7 @@ public class ModelReturn: JSONEncodable {
// MARK: JSONEncodable
func encodeToJSON() -> AnyObject {
var nillableDictionary = [String:AnyObject?]()
nillableDictionary["_return"] = self._return
nillableDictionary["return"] = self._return
let dictionary: [String:AnyObject] = APIHelper.rejectNil(nillableDictionary) ?? [:]
return dictionary
}

View File

@@ -11,6 +11,7 @@ import Foundation
public class Name: JSONEncodable {
public var name: Int?
public var snakeCase: Int?
public init() {}
@@ -19,6 +20,7 @@ public class Name: JSONEncodable {
func encodeToJSON() -> AnyObject {
var nillableDictionary = [String:AnyObject?]()
nillableDictionary["name"] = self.name
nillableDictionary["snake_case"] = self.snakeCase
let dictionary: [String:AnyObject] = APIHelper.rejectNil(nillableDictionary) ?? [:]
return dictionary
}

View File

@@ -18,7 +18,7 @@ public class SpecialModelName: JSONEncodable {
// MARK: JSONEncodable
func encodeToJSON() -> AnyObject {
var nillableDictionary = [String:AnyObject?]()
nillableDictionary["specialPropertyName"] = self.specialPropertyName
nillableDictionary["$special[property.name]"] = self.specialPropertyName
let dictionary: [String:AnyObject] = APIHelper.rejectNil(nillableDictionary) ?? [:]
return dictionary
}