从 Core Data 打印 NSError 的 userInfo 会抛出 EXC_BAD_ALLOC
我正在使用此代码(来自 iphone Core Data Unresolved error while保存)以打印 NSError 对象的更详细描述:
- (NSString*)debugDescription
{
NSMutableArray* errorLines = [NSMutableArray array];
[errorLines addObject:[NSString stringWithFormat:@"Failed to save to data store: %@", [self localizedDescription]]];
NSArray* detailedErrors = [[self userInfo] objectForKey:NSDetailedErrorsKey];
if (detailedErrors != nil && [detailedErrors count] > 0)
{
for (NSError* detailedError in detailedErrors)
{
// The following line crashes the app
[errorLines addObject:[NSString stringWithFormat:@" DetailedError: %@", [detailedError userInfo]]];
}
}
else
{
[errorLines addObject:[NSString stringWithFormat:@" %@", [self userInfo]]];
}
return [errorLines description];
}
问题是,每当我尝试访问嵌套 NSError 的 userInfo 对象时,应用程序就会崩溃并显示 EXC_BAD_ALLOC。
当我创建一个新的 NSManagedObject 并用数据填充它时,会生成有问题的错误。我在对象上分配的所有属性都保留分配给它们的所有属性,但似乎有些内容没有正确保留。
我怎样才能追踪到这个? NSZombieEnabled 没有告诉我任何有用的东西。
I'm using this code (from iphone Core Data Unresolved error while saving) to print a more detailed description of an NSError object:
- (NSString*)debugDescription
{
NSMutableArray* errorLines = [NSMutableArray array];
[errorLines addObject:[NSString stringWithFormat:@"Failed to save to data store: %@", [self localizedDescription]]];
NSArray* detailedErrors = [[self userInfo] objectForKey:NSDetailedErrorsKey];
if (detailedErrors != nil && [detailedErrors count] > 0)
{
for (NSError* detailedError in detailedErrors)
{
// The following line crashes the app
[errorLines addObject:[NSString stringWithFormat:@" DetailedError: %@", [detailedError userInfo]]];
}
}
else
{
[errorLines addObject:[NSString stringWithFormat:@" %@", [self userInfo]]];
}
return [errorLines description];
}
The problem is that whenever I attempt to access the userInfo object of a nested NSError, the app crashes with EXC_BAD_ALLOC.
The error in question is generated when I create a new NSManagedObject and populate it with data. All of the properties I'm assigning on the object retain whatever is assigned to them, but it seems like something is not being retained correctly.
How can I track this down? NSZombieEnabled didn't tell me anything useful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦。我将我的一列(以及相关的赋值属性)命名为“description”,这当然会覆盖 NSObject 的“description”方法,从而导致不好的结果。愚蠢的我。
Doh. I had named one of my columns (and associated assignment property) "description", which of course overrides NSObject's 'description' method, causing bad things. Stupid me.