Database Reference
In-Depth Information
about. Now when we receive a notification from an
NSManagedObjectContextDid-
SaveNotification
, we can easily filter the incoming objects against our predicate.
- (
void
)contextUpdated:(NSNotification*)notification
{
NSInteger totalCount = 0;
NSSet *temp = nil;
temp = [[notification userInfo] objectForKey:NSInsertedObjectsKey]
NSMutableSet *inserted = [temp mutableCopy];
if
([self masterPredicate]) {
[inserted filterUsingPredicate:[self masterPredicate]];
}
totalCount += [inserted count];
temp = [[notification userInfo] objectForKey:NSDeletedObjectsKey];
NSMutableSet *deleted = [temp mutableCopy];
if
([self masterPredicate]) {
[deleted filterUsingPredicate:[self masterPredicate]];
}
totalCount += [deleted count];
temp = [[notification userInfo] objectForKey:NSUpdatedObjectsKey];
NSMutableSet *updated = [temp mutableCopy];
if
([self masterPredicate]) {
[updated filterUsingPredicate:[self masterPredicate]];
}
totalCount += [updated count];
if
(totalCount == 0) {
return
;
}
NSMutableDictionary *results = [NSMutableDictionary dictionary];
if
(inserted) {
[results setObject:inserted forKey:NSInsertedObjectsKey];
}
if
(deleted) {
[results setObject:deleted forKey:NSDeletedObjectsKey];
}
if
(updated) {
[results setObject:updated forKey:NSUpdatedObjectsKey];
}
if
([[self delegate] respondsToSelector:[self action]]) {
[[self delegate] performSelectorOnMainThread:[self action]
withObject:self
waitUntilDone:YES];
}
}