-1

i have this code into core data model for update a value into it:

if (!([photo.photoDescription isEqualToString:[photoDictionary[PHOTO_DESCRIPTION] description]])) {
        photo.photoDescription = [photoDictionary[PHOTO_DESCRIPTION] description];
        photo.isOnMap = [NSNumber numberWithBool:NO];
        [context save:&error];
    }

in my controller i have add an observer for looking the changes into core data:

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificaRicevut) name:NSManagedObjectContextDidSaveNotification object:self.context];

when i execute the [context save:&error]; code, the notify is correctly sent, but when i make a request inside the notification method for retrieve the new value, i get the old value instead the new one. if i restart the app, the new value is show correctly. where is the problem? thanks

Max_Power89
  • 1,710
  • 1
  • 21
  • 38

2 Answers2

1

You could use PonyDebugger to inspect the database during run time. Problems like these are most often due to one of the following:

  • Not calling [managedObjectContext save:&error] correctly
  • Failing to create NSManagedObject or NSManagedObjectContext correctly
Daniel Larsson
  • 6,278
  • 5
  • 44
  • 82
1

i solved by putting this code inside the notification method:

    - (void)contextDidSave:(NSNotification *)notification
{
    dispatch_async(dispatch_get_main_queue(), ^{
        SEL selector = @selector(mergeChangesFromContextDidSaveNotification:);
        [self.context performSelectorOnMainThread:selector withObject:notification waitUntilDone:YES];
        [self updateMapWithPictureInCoreData];
    });
}

Hope can be helpful

Max_Power89
  • 1,710
  • 1
  • 21
  • 38