Odd behavior with NSPredicate and NSMutableArray
Merry Christmas Eve,
In the code below I've got two lines that create the NSPredicate 'searchPredicate' (they're both uncommented here, but in practice I alternate commenting one or the other out to test). When I use the testArray to create the predicate all is great and I get the results I expect, but when I use the self.currentDeckSwitchedOnCategoryArray I get zero results. I have checked many times to ensure both arrays have the same content (see console output below - differing the order of elements does not seem consequential). The only difference between the arrays is that one is an NSArray and the other is an NSMutableArray, although I have tried to convert the latter into an NSArray to see if that was the issue - no joy. Other ideas were the spaces in the strings or even that quotes appear around output in the console (typical when strings contain non-alphanumeric characters). Can anyone spot something that would cause this different behavior or suggest a fix to the problem?
Thanks and hope I can get this straightened out before Xmas day, Joel
>>>>>>>>>
NSArray* testArray = [[NSArray alloc] initWithObjects:@"Upper Body", @"Middle Body", @"Lower Body", @"Full Body", @"Wildcard", nil];
NSLog(@"self.currentDeckSwitchedOnCategoryArray values: %@", self.currentDeckSwitchedOnCategoryArray);
NSLog(@"testArray values: %@", testArray);
NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"(ANY Decks.Name == %@) && (Category IN %@)", [deckObject valueForKey:@"Name"], testArray];
NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"(ANY Decks.Name == %@) && (Category IN %@)", [deckObject valueForKey:@"Name"], self.currentDeckSwitchedOnCategoryArray];
[fetchRequest setPredicate:searchPredicate];
NSFetchedResultsController* tempFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
tempFetchedResultsController.delegate = self;
self.fetchedResultsController = tempFetchedResultsController;
>>>>>
2009-12-24 20:44:47.500 FDM_v2.0.25x[819:20b] testArray values: (
"Upper Body",
"Middle Body",
"Lower Body",
"Full Body",
Wildcard
)
2009-12-24 20:44:47.525 FDM_v2.0.25x[819:20b] self.currentDeckSwitchedOnCategoryArray: (
"Full Body",
"Upper Body",
"Middle Body",
"Lower Body",
Wildcard
)
|