[错误 localizedDescription] 上的 EXC_BAD_ACCESS;
此代码会引发 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]);
}
}
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]);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
既然你没有问,我想你想知道是什么导致了标题中的错误。
在我看来,你的查询返回了 0 个对象,并且你将该条件视为一个错误,而没有任何对象,因此错误从未初始化(它甚至没有分配),所以这就是为什么你会遇到不好的情况访问异常
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* 错误 = nil;
是正确的
这不是一个真正的问题。我搜索了这个,我花了很长时间才找到答案,所以就在这里!
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!