And*_*obs 6 iphone binary xcode core-data objective-c
我想知道将核心数据存储到二进制属性中是否是明智的选择
说我有一组电影,我想将图像DVD封面保存到一个属性,封面的平均大小为20/30kb(320x480px)
我想这样做的原因是为了存储管理,一旦我删除电影,我知道图像也被删除
我不太确定这是一个好主意,数据加载,速度?
有人有这方面的经验吗?
Ron*_*bro 11
在我看来,将图像存储在核心数据中并不是一个好主意,我很确定我也会在Apple的一个编程指南中阅读它.考虑到这一点,当您获取集合时,所有图像也将被加载到内存中,即使您只显示8个图像,您的整个图像集也将被核心数据加载.
如果您想确保删除移动记录时删除图像文件,我建议您通过managedObjectContext收听通知并删除电影时删除文件:
您可以注册willSave或didSave通知,每个通知都有自己的优点/缺点.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contextDidSave:) name:NSManagedObjectContextDidSaveNotification object:managedObjectContext];
Run Code Online (Sandbox Code Playgroud)
获取已删除的对象:
- (void) contextDidSave:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
for (NSManagedObject *currObject in [userInfo objectForKey:NSDeletedObjectsKey])
{
// Code for deleting file associated with the NSManagedObject, you can still
// access the managed object's properties.
}
}
Run Code Online (Sandbox Code Playgroud)