You can use FileAttributeKey.creationDate
to get the creation date of a file, and JSONSerialization
to parse the JSON file. Here's an example code snippet:
main.swift441 chars14 lines
In the attributes
dictionary, the value for the .creationDate
key is an optional Any
object, so you'll need to cast it to a Date
object before using it.
Note that the date formatter is not necessary in this case since creationDate
is already a Date
object. However, you may want to format the date string in a specific way for display purposes.
gistlibby LogSnag