It seems to me that storing images in a core data isn't a good idea, and I'm pretty sure I've also read it on one of Apple's programming guides. Just consider this, when you fetch your collection, all the images will also be loaded into memory, even if you're only displaying 8 images, your entire image collection will be loaded by core data.
If you want to make sure you delete the image files when a move record was deleted I suggest you listen to notifications by the managedObjectContext and delete files when a movie was deleted:
You can either register for the willSave or didSave notification, each with it's own advantages/disadvantages.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contextDidSave:) name:NSManagedObjectContextDidSaveNotification object:managedObjectContext];
Getting the deleted objects:
- (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.
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…