开发者

EXC_BAD_ACCESS on [error localizedDescription];

开发者 https://www.devze.com 2022-12-23 00:21 出处:网络
This Code trows an EXC_BAD_ACCESS: NSError* error; if(![appdelegate.managedObjectContext countForFetchRequest:requ开发者_如何学Pythonest error:&error]) {

This Code trows an EXC_BAD_ACCESS:

 NSError* error;
    if(![appdelegate.managedObjectContext countForFetchRequest:requ开发者_如何学Pythonest 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]);
        }
    }


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


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号