0

I have the following date formatter:

let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]

I want to pass that into a JSONEncoder, like this:

let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .formatted(formatter)

but that produces an error as it only accepts custom DateFormatters not ISO8601DateFormatters.

How can I do this?

Tometoyou
  • 6,720
  • 10
  • 54
  • 96
  • 2
    https://stackoverflow.com/questions/46458487/how-to-convert-a-date-string-with-optional-fractional-seconds-using-codable-in-s ? I guess you need to use `.custom` (and there is a sample on that answer) – Larme Apr 29 '22 at 09:36

0 Answers0