views:

254

answers:

3

This Code trows an EXC_BAD_ACCESS:

 NSError* error;
    if(![appdelegate.managedObjectContext countForFetchRequest:request error:&error]) {
        DLog(@"Failed to save to data store: %@", [error localizedDescription]);
        NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
        if(detailedErrors != nil && [detailedErrors count] > 0) {
            for(NSError* detailedError in detailedErrors) {
                DLog(@"  DetailedError: %@", [detailedError userInfo]);
            }
        }
        else {
            DLog(@"  %@", [error userInfo]);
        }
    }
A: 

NSError* error = nil;

is correct

This is not really a question. I searched for that and i took me long to find the answer so here it is!

david
well that skips the error message, but (without seeing the rest of the code) I think that your logic is not really correct. If error is nil, sending a message to it won't cause an error, but you're probably seeing bogus messages in the log anyway.
Victor Jalencas
+2  A: 

Since you don't ask, I assume you want to know what is causing the error in the title. Looks to me like your query returned 0 objects, and you are treating that condition as if it was an error when there was none, and so error was never initialized (it wasn't even allocated) so that's why you're getting a bad access exception

Victor Jalencas
A: 

You could try the Clang Static Analyzer... It's really helpful for searching leaks..

antihero