【发布时间】:2015-08-24 18:20:49
【问题描述】:
我有一个允许用户从网站下载图像的应用程序。 (玩具收藏家清单 2 - https://itunes.apple.com/us/app/toy-collector-checklist-2/id919363870?mt=8)
理论上,用户可以下载数千张图片,从而造成相当大的使用量。我正在尝试添加“删除所有图像”,以便用户可以在不删除应用的情况下清除图像。
代码似乎有效。按下按钮时图像不再可见,当我检查它时核心数据值返回“nil” - 但是当我进入我的使用设置时,空间似乎没有被释放。我正在使用我认为非常标准的获取和更新代码:
CoreDataHelper *cdh =
[(AppDelegate *)[[UIApplication sharedApplication] delegate] cdh];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Item"
inManagedObjectContext:cdh.context];
[fetchRequest setEntity:entity];
// [fetchRequest setPredicate:nil];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"photo != nil OR photoAlt != nil OR photoCam != nil"]];
[fetchRequest setFetchBatchSize:500];
NSManagedObject *removePhotoFromObject;
NSError *error = nil;
NSArray *results = [cdh.context executeFetchRequest:fetchRequest error:&error];
for (removePhotoFromObject in results) {
[removePhotoFromObject setValue:nil forKey:@"photoCam"];
[removePhotoFromObject setValue:nil forKey:@"photo"];
[removePhotoFromObject setValue:nil forKey:@"photoAlt"];
[removePhotoFromObject setValue:nil forKey:@"thumbnail"];
}
[cdh backgroundSaveContext];
这会将可能的照片位置的值设置为零。如果我再次运行相同的代码,它不会将它们添加到数组中(因为它们的值现在为零),所以我知道那部分正在工作。并且图像和缩略图被删除。但是,当我检查“设置”选项卡时,数据使用情况并没有改变。
有些事情可能会破坏工作:
项目是一个实体。 photo、photoAlt 和 photoCam 也是每个实体,与 Item 具有“To One”关系
它们在模型中都被归为“二进制数据”。
任何想法和建议将不胜感激。我查看了这些论坛以及更大的互联网,但到目前为止还没有找到解决方案。
扎克
【问题讨论】:
标签: ios sqlite core-data ios8 binary-data