Assuming you have a JSON which has a date property, you can represent the date in your Swift code as a Date
type. Here is how you can decode JSON data with date property using JSONDecoder
:
main.swift386 chars22 lines
Note that you need to set the dateDecodingStrategy
of your JSONDecoder
to .iso8601
to correctly decode the date from the JSON string. This will also work for other date formats, not just ISO 8601.
gistlibby LogSnag