Can't use in/contains operator with collection 1423 (not a collection)

Discussion in 'iOS Programming' started by isthisonetaken, Oct 19, 2012.

  1. isthisonetaken macrumors regular

    Jun 29, 2006
    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:
    - (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:

    But can't find anything in there that helps me solve my problem. Any ideas what could be going on?
  2. Sykte macrumors regular

    Aug 26, 2010
    NSNumber returns an what type of object?
    [NSNumber numberWithInteger:searchString.integerValue]
    What type of object does this class method accept as an argument?
     [NSPredicate predicateWithFormat:]
  3. isthisonetaken thread starter macrumors regular

    Jun 29, 2006
    It creates an NSNumber, and predicateWithFormat: expects a string. The line beneath that does create a string, and still contains the error however.
  4. CodeBreaker macrumors 6502

    Nov 5, 2010
    Sea of Tranquility
    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.

Share This Page