views:

89

answers:

1

I'm using this code (from http://stackoverflow.com/questions/1283960/iphone-core-data-unresolved-error-while-saving/1297157#1297157) 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.

A: 

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.

MikeQ