Reputation: 4232
I am getting the following error when creating the NSFetchedResultsController object
EDIT
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Subscriptions" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];
EDIT END
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
#0 0x977109c6 in __pthread_kill ()
#1 0x96296f78 in pthread_kill ()
#2 0x96287bdd in abort ()
#3 0x0022eb71 in uncaught_exception_handler ()
#4 0x024b70fc in __handleUncaughtException ()
#5 0x0264af0f in _objc_terminate ()
#6 0x052fb8de in safe_handler_caller ()
#7 0x052fb946 in std::terminate ()
#8 0x052fcab2 in __cxa_throw ()
#9 0x0264ade1 in objc_exception_throw ()
#10 0x00617f39 in -[NSFetchedResultsController initWithFetchRequest:managedObjectContext:sectionNameKeyPath:cacheName:] ()
Any ideas where I should start looking for the issue. This error helps in no way.
I have put a breakpoint and already checked the inputs There are two input to the init function, one is the managed object and the second is the fetch request.
both objects are valid, unlike mentiond in the answers below.
** Solution ** It appears that the sort descriptor is mandatory, thanks to Rog
Upvotes: 0
Views: 279
Reputation: 28339
Actually, that's a very helpful error. If you are going to program in objective-c, you need to get used to reading those stack traces.
It says that you gave initWithFetchRequest something bad to eat. In fact, it was so bad that it threw an exception. Furthermore, we know that you do not have an exception handler because std::terminate was called, and eventually the program aborted.
You can @catch the exception and handle it yourself to see the problem, or, better still, put a breakpoint to catch all exceptions (a good suggestion since in objective-c an exception is, actually, exceptional).
Click on the breakpoint pane (on the left, with the right-arrow looking icon). At the bottom is a little +. Click it. Select "Add Exception Breakpoint" and have it break on all exceptions at the point that they are thrown.
Now, you can look at the actual exception, and it will guide you. Most likely, it will tell you that the fetch request is not configured properly. It could also be that you fed it a bad MOC, or other parameter.
Upvotes: 3