Ox Smith
Ox Smith

Reputation: 509

CoreData: error: Serious application error. Exception was caught during Core Data change processing

I am running into major issues developing my iphone app.

here is the full error:

CoreData: error: Serious application error.  Exception was caught during Core Data 
change processing.  This is usually a bug within an observer of 
NSManagedObjectContextObjectsDidChangeNotification.  -[TimeSpentStudying coordinate]:
unrecognized selector sent to instance 0x21db92d0 with userInfo (null)

This is weird because I have two coreData entities ( Locations & TimeSpentStudying). But I dont think those are the problems. [TimeSpentStudying coordinate] is weird, because I do not have a coordinate property sent on TimeSpentStudying core data class

I have a mapView set up, and when a user taps on the detail disclosure button on an mkannotationview, a new view (LibraryTrackTimeViewController) pops up, but is pretty much unusable. I tried calling NSLog in viewDidLoad and nothing showed up.

mapViewController.m

#pragma mark - NSNotification

- (void)contextDidChange:(NSNotification *)notification
{
  if ([self isViewLoaded]) {
    [self updateLocations];
}

.

- (void)updateLocations
{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Location" inManagedObjectContext:self.managedObjectContext];

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];

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];

}

-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
    name:NSManagedObjectContextObjectsDidChangeNotification
    object:self.managedObjectContext];
}

the error I think might have to do with the prepareForSegue method in mapViewController.m

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  if (distance < 500) {
  if ([segue.identifier isEqualToString:@"TrackLibraryTimes"]) {
    UINavigationController *navigationController = segue.destinationViewController;

LibraryTrackTimeViewController *controller = (LibraryTrackTimeViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
  }
 }}

I apologize for the rough syntax, I am just getting used to SO, if you need any more code, please let me know, thanks all.

Upvotes: 13

Views: 10131

Answers (4)

Michael McKenna
Michael McKenna

Reputation: 794

Fixed the issue by deallocating the fetched results controller. It was still performing fetches as I was adding/editing objects in a separate screen.

Upvotes: 2

DogCoffee
DogCoffee

Reputation: 19946

I had same error, due to

-(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath

case NSFetchedResultsChangeInsert:
            //[self.tableView insert
            NSLog(@"change insert");
            [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
            break;

I had used indexPath instead of newIndexPath.

Upvotes: 8

Harish
Harish

Reputation: 1519

COuple of things I would try.

  1. Delete the application from simulator and clean the app and run again.

  2. Looking at your code, I feel you are passing around the managedContextObject from one controller to another, no need to do that. User AppDelegate sharedInstance to get managedObject whenever you want. It's not going to create multiple instances, it's a singleton object.

Try these two and hopefully, you might find some answer or may be fix it.

Upvotes: -3

birikino
birikino

Reputation: 71

Depending on the complexity of your project, a quick way to catch this is to implement the offending method and set a breakpoint there. When you hit the breakpoint, you can see where it was called, and Bob's your uncle.

So you could put something like

- (CLLocationCoordinate2D)coordinate{
    // set a breakpoint on the next line
    NSParameterAssert(false);
    return nil;
}

in your TimeSpentStudying class and see where it gets called.

Just make sure you delete it when you're done.

Upvotes: 1

Related Questions