Tom*_*eit 2 persistence objective-c ios
我知道这种方法:resourceValueForKeys给定一个NSURL和一组键将为您获取文件的属性......但我需要的是枚举给定NSURL目录中的所有文件并为我提供属性的东西。
我尝试在NSFileSystem课堂上使用枚举器执行此操作,但无法使其正常工作,有人知道这样做的正确方法吗?...我没有使用 Core Data。
NSDictionary *values = [fileDirectory resourceValuesForKeys:@[NSURLAttributeModificationDateKey] error:nil];
NSLog(@"object: %@", values);
Run Code Online (Sandbox Code Playgroud)
干得好:
NSString *path = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/your file path"];
NSLog(@"Your path: %@",path);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSDictionary *attributesOfYourItem = [fileManager attributesOfItemAtPath:path error:&error];
if(error)
NSLog(@"Error: %@",error);
else
NSLog(@"Attribute dictionary: %@",attributesOfYourItem);
Run Code Online (Sandbox Code Playgroud)