Skip to content

Commit f50174e

Browse files
committed
Merge pull request #2077 from spotby/swift-java-date
adding support for java dates
2 parents fe2715c + cdc9fb5 commit f50174e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

modules/swagger-codegen/src/main/resources/swift/Models.mustache

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,19 @@ class Decoders {
109109
}
110110
// Decoder for NSDate
111111
Decoders.addDecoder(clazz: NSDate.self) { (source: AnyObject) -> NSDate in
112-
let sourceString = source as! String
113-
for formatter in formatters {
114-
if let date = formatter.dateFromString(sourceString) {
115-
return date
112+
if let sourceString = source as? String {
113+
for formatter in formatters {
114+
if let date = formatter.dateFromString(sourceString) {
115+
return date
116+
}
116117
}
118+
117119
}
118-
fatalError("formatter failed to parse \(sourceString)")
120+
if let sourceInt = source as? Int {
121+
// treat as a java date
122+
return NSDate(timeIntervalSince1970: Double(sourceInt / 1000) )
123+
}
124+
fatalError("formatter failed to parse \(source)")
119125
} {{#models}}{{#model}}
120126

121127
// Decoder for [{{{classname}}}]

0 commit comments

Comments
 (0)