| //
“// #{@class_name}.swift”¶ ↑
| //
| import Foundation
“final class #{@class_name}: ResponseObjectSerializable, ResponseCollectionSerializable {”¶ ↑
-
@columns.each do |col|
-
if col.not_null
“var #{col.formatted_name}:#{col.formatted_type}?”¶ ↑
-
else
“var #{col.formatted_name}:#{col.formatted_type}?”¶ ↑
| init?(response: NSHTTPURLResponse, representation: AnyObject) {
-
@columns.each do |col|
-
if col.type == “string”
“self.#{col.formatted_name} = (representation.valueForKey(‘#{col.name}’) as? String) ?? ””¶ ↑
-
elsif col.type == “integer”
“self.#{col.formatted_name} = (representation.valueForKey(‘#{col.name}’) as? Int) ?? -1”¶ ↑
-
elsif col.type == “float”
“self.#{col.formatted_name} = (representation.valueForKey(‘#{col.name}’) as? Float) ?? -1.0”¶ ↑
-
elsif col.type == “datetime”
“self.#{col.formatted_name} = NSDate.fromRails(representation.valueForKey(‘#{col.name}’) as? String ?? ”)”¶ ↑
-
if col.not_null
“assert(representation.valueForKey(‘#{col.name}’) != nil, ‘Expected #{col.name} to not be nil.’)”¶ ↑
-
| }
“class func collection(response response: NSHTTPURLResponse, representation: AnyObject) -> [#{@class_name}] {”¶ ↑
| let xarray = representation as! [AnyObject] = "let mapped:[ #{@class_name}?] = xarray.map({ #{@class_name}(response: response, representation: $0) })" = "return mapped.filter({ (element:#{@class_name}?) -> Bool in" | if let _ = element { | return true | } | return false = "}).map({ (element) -> #{@class_name} in" | return element! | })
| }
| func toDict() -> [String: AnyObject] {
| let dict:[String:AnyObject?] = [ - @columns.each do |col| - line = "" - if col.type == "string" - line = "'#{col.name}':#{col.formatted_name}" - elsif col.type == "integer" - line = "'#{col.name}':#{col.formatted_name}" - elsif col.type == "float" - line = "'#{col.name}':#{col.formatted_name}" - elsif col.type == "datetime" - line = "'#{col.name}':#{col.formatted_name}.railsFriendly()" - end - line += "," if col != @columns.last = line - end | ] return removeNilValuedKeys(dict)
| }
-
| }