My program is crashing as a result of the runtime sending isEqualToString: to a NSNull object. I cannot find where this NSNull is coming from; I never explicitly create one. I also can't find at all who or what is calling isEqualToString.
My understanding is that NSNull is an objected used only to get around the fact that you cannot add nil to a collection. My program does create several auto-release arrays; so I am guessing one of them is somehow ending up with an NSNull in it. The odd part is that none of these arrays are supposed to contain any NSString objects, which means that isEqualToString: would cause a crash if it were sent to an object in my array anyway.
I am creating these arrays with CoreData fetch requests and predicates:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"property.name CONTAINS[cd] %@ OR client.name CONTAINS[cd] %@", self.searchDisplayController.searchBar.text, self.searchDisplayController.searchBar.text];
request.entity = [NSEntityDescription entityForName:@"SearchIndex" inManagedObjectContext:appDelegate.rootViewController.managedObjectContext];
request.predicate = predicate;
[request setFetchLimit:0];
NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"client" ascending:YES];
NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"property" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, sortDescriptor2, nil];
request.sortDescriptors = sortDescriptors;
[sortDescriptors release];
[sortDescriptor1 release];
[sortDescriptor2 release];
NSError *error = nil;
NSFetchedResultsController *controller = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:appDelegate.managedObjectContext sectionNameKeyPath:@"client" cacheName:nil];
self.resultsController = controller;
[controller release];
[self.resultsController performFetch:&error];
[request release];
Later I further filter the fetchedResults like this:
id <NSFetchedResultsSectionInfo> sectionInfo = [self.resultsController.sections objectAtIndex:section];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"property.name CONTAINS[cd] %@", self.searchDisplayController.searchBar.text];
NSArray *array = [sectionInfo.objects filteredArrayUsingPredicate:predicate];
return [array valueForKey:@"property"];
What could cause an NSNull to end up in one of these arrays? Looking at the arrays after they are created, I don't see any NSNull objects. Is there anything else that could cause an NSNull to get created, specifically to get created in a place where the system is expecting an NSString instead? Is there anyway to use the debugger to track down where the isEqualToString: message is actually being sent? (If I'm stepping through, it happens after all my code is executed, my guess was somewhere where things are being autoreleased).
Thanks!