gpt4 book ai didi

iphone - 检查文件是否更新

转载 作者:行者123 更新时间:2023-12-01 17:57:15 24 4
gpt4 key购买 nike

我有iOS应用程序。在文件目录中有一些文件。我需要检查这些文件是否已被编辑或替换。正确的做法是什么?我应该对文件进行某种哈希处理还是最后一次编辑时间(如何在iOS中获得该时间)还是有一些更好的方法来实现呢?

最佳答案

您可以使用以下代码获取文件修改日期:

NSFileManager* fileManager = [NSFileManager defaultManager];
NSDictionary* attributes = [fileManager attributesOfItemAtPath:path error:nil];

if (attributes != nil) {
NSDate *date = (NSDate*)[attributes objectForKey:NSFileModificationDate];
NSLog(@"Last modification date: %@", [date description]);
} else {
NSLog(@"Not found");
}

here您可以找到 attributesOfItemAtPath:error:函数的文档,而 here您可以获取的文件属性列表

关于iphone - 检查文件是否更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15189334/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com