Friday, 30 August 2013

executeFetchRequest hangs and never returns error or proceeds

executeFetchRequest hangs and never returns error or proceeds

I'm using the AppDelegate's default managedObjectContext, and when I
executeFetchRequest on it, it never goes to the next line or crashes with
an error. This is on a background thread, so the UI does not freeze, but
the data is never populated -- my activity indicator never stops and my
debugging tell me it never gets off that statement. I stepped through each
line, and I narrowed it down to the executeFetchRequest method. What might
be causing this? There are no objects saved, but I don't think that should
have anything to do with it. So far, it's been an hour, so something has
gone wrong clearly. Lastly, this only happens like 40% of the time.
Here's what the code looks like:
NSSortDescriptor *byTimestamp = [NSSortDescriptorWithKey:@"timestamp"
ascending:NO];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]
initWithEntityName:@"Message"];
[fetchRequest setSortDescriptors:@[byTimestamp]];
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSArray *messages = [managedObjectContext executeFetchRequest:fetchRequest
error:&error];//hangs on this line!!
if(error != nil)
NSLog(@"Error: %@", [error localizedDescription]);

No comments:

Post a Comment