Thanks to a variety of helpful posts in this forum, I have some code that works for obtaining the Creation Date of a single user-selected NSURL. However, I cannot get the c
According to the header doc of URL
and URLResourceValues
, you may need to write something like this:
(This code is assuming chosenURL
is of type URL?
.)
do {
if
let resValues = try chosenURL?.resourceValues(forKeys: [.creationDateKey]),
let createDate = resValues.creationDate
{
//Use createDate here...
}
} catch {
//...
}
(If your chosenURL
is of type NSURL?
, try this code.)
do {
if
let resValues = try (chosenURL as URL?)?.resourceValues(forKeys: [.creationDateKey]),
let createDate = resValues.creationDate
{
//Use createDate here...
print(createDate)
}
} catch {
//...
}
I recommend you to use URL
rather than NSURL
, as far as you can.