如何解决fileAttributesAtPath警告的问题?

时间:2012-01-26 14:12:51

标签: objective-c ios warnings

现在我使用这段代码:

NSDictionary* attr = [[NSFileManager defaultManager] fileAttributesAtPath:file traverseLink:YES];

并收到警告:

'fileAttributesAtPath:traverseLink:' is deprecated

谁知道要使用什么呢?

谢谢!

5 个答案:

答案 0 :(得分:8)

改为使用attributesOfItemAtPath:error:

答案 1 :(得分:4)

使用attributesOfItemAtPath:error:

NSError* error;
NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:file error:&error];

答案 2 :(得分:1)

接受的答案忘记了处理问题的traverseLink:YES

改进的答案是同时使用attributesOfItemAtPath:error:stringByResolvingSymlinksInPath

NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:[file stringByResolvingSymlinksInPath] error:nil];

答案 3 :(得分:0)

特别注意事项

由于此方法不返回错误信息,因此自Mac OS X v10.5起已弃用。 使用setAttributes:ofItemAtPath:错误:改为:

link

答案 4 :(得分:0)

你应该阅读documentation

  

fileAttributesAtPath:traverseLink:

     

返回描述文件POSIX属性的字典   指定的。 (在Mac OS X v10.5中不推荐使用   attributesOfItemAtPath:error:代替。)