How can I get the file creation date using URL resourceValues method in Swift 3?

前端 未结 3 983
耶瑟儿~
耶瑟儿~ 2020-12-19 14:23

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

3条回答
  •  感情败类
    2020-12-19 14:34

    in swift 5 I use the following code:

    let attributes = try! FileManager.default.attributesOfItem(atPath: item.path)
    let creationDate = attributes[.creationDate] as! Date
    

    sort array with the following code

    fileArray = fileArray.sorted(by: {
            $0.creationDate.compare($1.creationDate) == .orderedDescending
        })
    

    more about FileAttributeKey here: https://developer.apple.com/documentation/foundation/fileattributekey

提交回复
热议问题