title: How to use multiple NSPredicates for multiple search values
body: <p>I'm using a UITextField as a search field: The user can input multiple search values separated by comma. By typing I want to find every custom object in my NSArray that matches one of the search component.</p>
  
  <p>My custom objects have no properties (that can be used for the search). Receiving a value I have to call <code>[myObject fieldForKey:@"username"].value;</code>. Because of this I have to use <code>[NSPredicate predicateWithBlock]</code> (or another way was not possible for me).</p>
  
  <p>My method for the search (will be called whenever a character was changed in the TextField):</p>
  
  <pre><code>-(void)searchEntriesWithString:(NSString*)searchString {
      NSArray *dataSource = [NSArray arrayWithArray:_allObjects];
  
      searchString = [searchString stringByReplacingOccurrencesOfString:@" " withString:@""];
  
      NSArray *components = [searchString componentsSeparatedByString:@","];
      NSMutableArray *predicates = [NSMutableArray array];
      for (NSString *value in components) {
          NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
  
          return ( [[(MyObject*)evaluatedObject fieldForKey:@"username"].wert hasPrefix:value ]);
          }];
  
          [predicates addObject:predicate];
      }
  
          NSPredicate *resultPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:predicates];
  
      NSMutableArray searchResultArray = [NSMutableArray arrayWithArray:[dataSource filteredArrayUsingPredicate:resultPredicate]];
  }
  </code></pre>
  
  <p>Assuming following dataSource:</p>
  
  <ul>
  <li>Object1 with username "userA"</li>
  <li>Object2 with username "userB"</li>
  <li>Object3 with username "userC"</li>
  </ul>
  
  <p>Calling the method with '[self searchEntriesWithString:@"userA,userB"]' should result in an array with Object1 and Object2.</p>
  
  <p>But I don't get this result.</p>