diff --git a/modules/swagger-codegen/src/main/resources/swift/Models.mustache b/modules/swagger-codegen/src/main/resources/swift/Models.mustache index 587b710326b..31c055b54dc 100644 --- a/modules/swagger-codegen/src/main/resources/swift/Models.mustache +++ b/modules/swagger-codegen/src/main/resources/swift/Models.mustache @@ -97,17 +97,24 @@ class Decoders { static private func initialize() { dispatch_once(&once) { - let dateTimeFormatter = NSDateFormatter() - dateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" - let dateFormatter = NSDateFormatter() - dateFormatter.dateFormat = "yyyy-MM-dd" + let formatters = [ + "yyyy-MM-dd", + "yyyy-MM-dd'T'HH:mm:ssZZZZZ", + "yyyy-MM-dd'T'HH:mm:ss'Z'" + ].map { (format: String) -> NSDateFormatter in + let formatter = NSDateFormatter() + formatter.dateFormat = format + return formatter + } // Decoder for NSDate Decoders.addDecoder(clazz: NSDate.self) { (source: AnyObject) -> NSDate in let sourceString = source as! String - if count(sourceString) == 10 { - return dateFormatter.dateFromString(sourceString)! + for formatter in formatters { + if let date = formatter.dateFromString(sourceString) { + return date + } } - return dateTimeFormatter.dateFromString(sourceString)! + fatalError("formatter failed to parse \(sourceString)") } {{#models}}{{#model}} // Decoder for {{{classname}}}