问题是删除使用方法编写的项目writeToFile:
,我似乎无法删除它。我试过 NSFileManager 但我猜这是两种不同类型的存储。
- (BOOL) removeObject: (NSString *)objectToRemove inCategory:(StorageType)category
{
BOOL result = NO;
NSError *removeError;
NSString *storageFolder = [self getCategoryFor:category];
if (objectToRemove) {
NSFileManager *fileManager = [[NSFileManager alloc]init];
// Find folder
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:storageFolder];
NSString *dataPathFormated = [dataPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) {
NSLog(@"Removing file error: folder was not found");
}
NSURL *destinationURL = [[NSURL alloc]initWithString:[NSString stringWithFormat:@"%@/%@",dataPathFormated,objectToRemove]];
//NSString *destinationString = [NSString stringWithFormat:@"%@/%@",dataPath,objectToRemove];
if ([fileManager fileExistsAtPath:[destinationURL path]]) {
NSLog(@"destination URL for file to remove: %@", destinationURL);
// Remove object
result = [fileManager removeItemAtURL:destinationURL error:&removeError];
NSLog(@"ERROR REMOVING OBJECT: %@",removeError);
} else {
NSLog(@"Object to remove was not found at given path");
}
}
return result;
}
我使用 NSData 的方法添加对象writeToFile
,我想这一定是问题所在,因为它使用 plist 来存储 NSData 其他东西,如果是 - 我如何删除这个用 编写的项目writeToFile
?:
[object writeToFile:destinationString atomically:YES];
删除文件的错误消息
错误删除对象:错误域 = NSCocoaErrorDomain 代码 = 4“操作无法完成。(可可错误 4。)”用户信息 = 0xd4c4d40 {NSURL =/用户/布鲁克/图书馆/应用程序%20支持/iPhone%20模拟器/6.1/ Applications/14480FD3-9B0F-4143-BFA4-728774E7C952/Documents/FavoritesFolder/2innernaturemusic}