How to convert a date string with optional fractional seconds using Codable in Swift4
I am replacing my old JSON parsing code with Swift's Codable and am running into a bit of a snag. I guess it isn't as much a Codable question as it is a DateFormatter question. Start with a struct struct JustADate: Codable { var date: Date } and a json string let json = """ { "date": "2017-06-19T18:43:19Z" } """ now lets decode let decoder = JSONDecoder() decoder.dateDecodingStrategy = .iso8601 let data = json.data(using: .utf8)! let justADate = try! decoder.decode(JustADate.self, from: data) //all good But if we change the date so that it has fractional seconds, for example: let json = """ {