How can I get the file creation date using URL resourceValues method in Swift 3?
<p>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 code to work for either a hard-coded NSURL, nor within a loop through an NSFileManager enumerator.</p>

<p>I am not a professional programmer; I make apps that are tools for office.  My ultimate goal is to simply sort an Array of NSURL objects based on Creation Date.  </p>

<p>The code I am using is below, which functions just fine as is, but if I try to use the commented line to evaluate a specific PDF file, I get the following error:</p>

<p><a href="https://i.stack.imgur.com/Hbia3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hbia3.png" alt="enter image description here"></a></p>

<p>I get the exact same error when I try to add this code to a loop of NSURL objects procured via the NSFileManager Enumerator.</p>

<p>I cannot figure out how to use the error instruction to solve the problem.  If anyone can assist, that would be tremendous.  Thank you.</p>

<pre><code>let chosenURL = NSOpenPanel().selectFile

    //let chosenURL = NSURL.fileURL(withPath: "/Users/craigsmith/Desktop/PDFRotator Introduction.pdf")

    do
    {
        var cr:AnyObject?
        try chosenURL?.getResourceValue(&amp;cr, forKey: URLResourceKey.creationDateKey)

        if (cr != nil)
        {
            if let createDate = cr as? NSDate
            {
                print("Seems to be a date: \(createDate)")

                let theComparison = createDate.compare(NSDate() as Date)

                print("Result of Comparison: \(theComparison)")  // Useless

                let interval = createDate.timeIntervalSinceNow

                print("Interval: \(interval)")

                if interval &lt; (60*60*24*7*(-1))
                {
                    print("More than a week ago")

                }
                else
                {
                    print("Less than a week ago")
                }
            }
            else
            {
                print("Not a Date")
            }
        }
    }
    catch
    {

    }
</code></pre>