I´m currently working on an ipad app in which I fetch a lot of data with core data. To keep memory profile low I´m setting the requests resultType to NSManagedObjectIDResultType and grabbing objects with the -objectWithID: Method whenever I need real data.
Everything works as expected. The problem is when it comes to adding/removing Objects from my table view (from the context). Thats a piece of code I call in my tableView:commitEditingStyle:forRowAtIndexPath:
if(editingStyle == UITableViewCellEditingStyleDelete)
{
NSManagedObjectID *ID = [fetchedResultsController objectAtIndexPath: indexPath];
NSManagedObject *objectToDelete = [self.managedObjectContext objectWithID: ID];
[self.managedObjectContext deleteObject: objectToDelete];
[self.managedObjectContext save: nil];
}
It throws me an exception: "* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[_NSObjectID_48_0 objectID]: unrecognized selector sent to instance 0x5e56900'"
Trace:
#0 0x9953cef6 in __kill
#1 0x9953cee8 in kill$UNIX2003
#2 0x995cf62d in raise
#3 0x995e56e4 in abort
#4 0x95826fda in __gnu_cxx::__verbose_terminate_handler
#5 0x02d9d61c in _objc_terminate
#6 0x9582517a in __cxxabiv1::__terminate
#7 0x958251ba in std::terminate
#8 0x958252b8 in __cxa_throw
#9 0x02d9d3d8 in objc_exception_throw
#10 0x02c84a5b in -[NSObject doesNotRecognizeSelector:]
#11 0x02c01676 in ___forwarding___
#12 0x02c009f2 in __forwarding_prep_0___
#13 0x0281f0f7 in -[_PFBatchFaultingArray arrayFromObjectIDs]
#14 0x0281fe4b in -[_PFMutableProxyArray managedObjectIDAtIndex:]
#15 0x0281ec8e in -[_PFMutableProxyArray indexOfManagedObjectForObjectID:]
#16 0x028823b8 in -[NSFetchedResultsController(PrivateMethods) _preprocessDeletedObjects:deletesInfo:sectionsWithDeletes:]
#17 0x02885159 in -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:]
#18 0x00065586 in _nsnote_callback
#19 0x02beb165 in _CFXNotificationPostNotification
#20 0x0005c2ca in -[NSNotificationCenter postNotificationName:object:userInfo:]
#21 0x027d838d in -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:]
#22 0x0283fe83 in -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:]
#23 0x027b9af6 in -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:]
#24 0x027f4a61 in -[NSManagedObjectContext save:]
#25 0x0035d361 in -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:]
#26 0x00306cee in -[UIApplication sendAction:to:from:forEvent:]
#27 0x0038043e in -[UIControl sendAction:to:forEvent:]
#28 0x003828c0 in -[UIControl(Internal) _sendActionsForEvents:withEvent:]
#29 0x0038146d in -[UIControl touchesEnded:withEvent:]
#30 0x00325de8 in -[UIWindow _sendTouchesForEvent:]
#31 0x0030b643 in -[UIApplication sendEvent:]
#32 0x003131d8 in _UIApplicationHandleEvent
#33 0x0351617c in PurpleEventCallback
#34 0x02bd289c in CFRunLoopRunSpecific
#35 0x02bd18a8 in CFRunLoopRunInMode
#36 0x0351489d in GSEventRunModal
#37 0x03514962 in GSEventRun
#38 0x00311372 in UIApplicationMain
#39 0x00002436 in main at main.m:14
I assume this is an issue with the NSFetchedResultsController and NSManagedObjectIDs. When I set its delegate to nil its not crashing (even crashes with empty delegate methods).
Any idea? Would it be a good idea if I get rid of the NSFetchedResultsController and doing updates manually by observing NSManagedObjectContext notifications?