我想将文件保存到一个文件夹,然后检索该文件夹中的所有内容检索项目,所以我做的:iOS的持久性:存储和目录
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:storageFolder];
// StorageFolder is just a string like: "@"/FavoritesFolder"
// Filename is just a title given like "myTune.mp3"
NSString *destinationString = [NSString stringWithFormat:@"%@/%@",dataPath,filename];
BOOL success = [object writeToFile:destinationString atomically:YES];
然后我想检索对象,所以我做
NSArray *dirContents = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:dataPath error:nil];
但我得到的filename
阵列(如myTune.mp3)。而不是Object
这是一个NSDictionary。我究竟做错了什么?
备注 - 不要使用'stringWithFormat:'来建立你的路径。这样做:'NSString * destinationString = [dataPath stringByAppendingPathComponent:filename];' – rmaddy