Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

isthisonetaken

macrumors regular
Original poster
Jun 29, 2006
123
0
Hi All,

I have an iPhone app that has a table with search functionality. I have a weird bug, where if I come from one tab into this table (doesn't happen if I go directly into the tab with the table) and choose to search, it crashes with the error code that I set as the title: Can't use in/contains operator with collection 1423 (not a collection) where 1423 changes between runs. I have a core data entity which has a NSNumber attribute which I'm trying to search.

What I do is this:
Code:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    NSPredicate *searchPredicate = nil;
    
    if (searchString.length > 0) {
        // set the predicate
        searchPredicate = [NSPredicate predicateWithFormat:@"number contains %@", [NSNumber numberWithInteger:searchString.integerValue]];
// searchPredicate = [NSPredicate predicateWithFormat:@"number contains %@", searchString];
// the above line doesn't work either
    }
    
    [self setupFetchedResultsControllerForPredicate:searchPredicate];
    return YES;
}

From doing a Google search, I found this: http://stackoverflow.com/questions/...e-sometimes-throws-nsinvalidargumentexception

But can't find anything in there that helps me solve my problem. Any ideas what could be going on?
 
Code:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    NSPredicate *searchPredicate = nil;
    
    if (searchString.length > 0) {
        // set the predicate
        searchPredicate = [NSPredicate predicateWithFormat:@"number contains %@", [NSNumber numberWithInteger:searchString.integerValue]];
// searchPredicate = [NSPredicate predicateWithFormat:@"number contains %@", searchString];
// the above line doesn't work either
    }
    
    [self setupFetchedResultsControllerForPredicate:searchPredicate];
    return YES;
}

NSNumber returns an what type of object?
Code:
[NSNumber numberWithInteger:searchString.integerValue]

What type of object does this class method accept as an argument?
Code:
 [NSPredicate predicateWithFormat:]
 
It creates an NSNumber, and predicateWithFormat: expects a string. The line beneath that does create a string, and still contains the error however.
 
It creates an NSNumber, and predicateWithFormat: expects a string. The line beneath that does create a string, and still contains the error however.

I am not very sure, but I feel numeric comparisons should not support the CONTAINS keyword. It should work for strings only. So If you can, change the entity attribute from NSNumber to NSString, and modify your predicate likewise.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.