Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
I'm just starting out with Core Data and I need some help.

At the moment I fetch all of the objects in Core Data, instead of just the ones that have changed.

My controller listens out for NSNotifications from CoreData. I want to use the notification.userInfo dictionary to specify which objects need to be retrieved from Core Data.

How can I change the following method to make use of the dictionary? How do I set up a predicate?

Code:
-(void)updateLocations:(NSDictionary*)dictionary
{
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Location" inManagedObjectContext:self.managedObjectContext];
    
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    [fetchRequest setEntity:entity];
    
    NSLog(@"fish: Dictionary: %@ :fish", dictionary);
    
    NSError *error;
    NSArray *foundObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
    if (foundObjects == nil) {
        FATAL_CORE_DATA_ERROR(error);
        return;
    }
    
    if (locations != nil) {
        [self.mapView removeAnnotations:locations];
    }
    
    locations = foundObjects;
    [self.mapView addAnnotations:locations];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.