1

我正在使用此代码(来自iphone Core Data Unresolved error while Saving)打印 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 没有告诉我任何有用的信息。

4

1 回答 1

2

多哈。我将我的一个列(以及相关的赋值属性)命名为“description”,这当然会覆盖 NSObject 的“description”方法,从而导致不好的事情。愚蠢的我。

于 2010-09-21T00:09:21.870 回答