Why is CoreData syntax required after uninstalling on an iPad but not an iPhone?

When the following code runs on iPhone (ios 3.1), the number of selected objects after deletion is less than before deletion. But on the iPad (ios 3.2), the count remains unchanged. This inconsistency caused the iPad to crash, since fetchedObjects is called in another place of the code shortly after the deletion and the calling code, trusting the account, tries to access the properties of the newly deleted objects, which leads to an NSObjectInaccessibleException error (see below). The fix was to use this commented out call to performFetch, which when you execute the second call to fetchObjects gives the same result as on an iPhone without it. My question is: why does the iPad produce different results than the iPhone? This is the second of these differences that I recently discovered and published.

-(NSError*)deleteObject:(NSManagedObject*)mo; { NSLog(@"\n\nNum objects in store before delete: %i\n\n", [[self.fetchedResultsController fetchedObjects] count]); [self.managedObjectContext deleteObject:mo]; // Save the context. NSError *error = nil; if (![self.managedObjectContext save:&error]) { } // [self.fetchedResultsController performFetch:&error]; // force a fetch NSLog(@"\n\nNum objects in store after delete (and save): %i\n\n", [[self.fetchedResultsController fetchedObjects] count]); return error; } 

(Full NSObjectInaccessibleException: "Application terminated due to an uncaught exception" NSObjectInaccessibleException ", reason:" CoreData could not execute error for "0x1dcf90"

+7
iphone ipad core-data
source share
3 answers

Adding the following code to your FRC delegate will resolve this.

 - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { } 

Thanks to BenT on the Apple Dev forum for the answer (see my comments above). I asked him for an explanation of the fix, and he said: β€œThe iPad uses iPhoneOS 3.2, while iPhones 3.1. NSFetchedResultsController in 3.2 made a few improvements, but unfortunately, the side effect of delegate requirements is to actually implement one ( any) of the delegate methods for actively tracking changes. " https://devforums.apple.com/message/221471#221471 (I hope this helps someone. FAK said that in such cases you can answer your own question)

+6
source share

Keep in mind that the created control controller caches data in order to speed up its work. After deleting the object, you can also call + (void) deleteCacheWithName: make sure that the deleted object does not linger in the cache. That is, if you are not using delegate calls.

0
source share

Adding a delegate method didn't solve my problem. But I solved this by adding a forced performFetch after the deletion was completed. I also delete the cache before fetching.

I'm on iOS 4.1.

0
source share

All Articles