You can use the FileManager
class provided by Apple to get the file attributes for the directory, which includes the creation date. Here's an example:
main.swift362 chars12 lines
The attributesOfItem(atPath:)
method returns a dictionary of file attributes for the file or directory at the specified path. The creation date is stored in the FileAttributeKey.creationDate
key of the dictionary, so we can retrieve it from there as a Date
object. If an error occurs while retrieving the attributes, the catch
block will print the error message.
gistlibby LogSnag