【发布时间】:2021-12-24 23:05:46
【问题描述】:
我需要一种检查文件上次打开时间的方法。我尝试通过创建自定义 FileAttributeKey 并将其设置为当前日期,但是当我再次打开文件时,该属性不存在:
private let key = FileAttributeKey(rawValue: "lastOpenedAt")
do {
try FileManager.default.setAttributes(
[key: Date()],
ofItemAtPath: videoNameDirectoryPath
)
} catch {
Log.error(error.localizedDescription)
}
所以现在我使用修改日期键来说明我上次打开文件的时间,这并不理想,所以我想知道是否有更好的方法来做到这一点
【问题讨论】:
-
setAttributes会抛出错误吗?
标签: swift nsfilemanager file-attributes