title: iOS CoreData NSPredicate to query multiple properties at once
body: <p>I am trying to use a <code>UISearchBar</code> to query multiple properties of a <code>NSManagedObject</code>
  I have a <code>NSManagedObject</code> called <code>Person</code>, every person has a <code>name</code> and <code>socialSecurity</code> property.  Right now my code can perform a search (fetch) for one of those properties or the other, but not both at the same time.</p>
  
  <pre><code>- (void) performFetch
  {       
      [NSFetchedResultsController deleteCacheWithName:@"Master"];  
  
      // Init a fetch request
      NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
      NSEntityDescription *entity = [NSEntityDescription entityForName:@"MainObject" inManagedObjectContext:self.managedObjectContext];
      [fetchRequest setEntity:entity];
  
      // Apply an ascending sort for the color items
      //NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Term" ascending:YES selector:nil];
      NSSortDescriptor *sortDescriptor;
      sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"fullName" ascending:YES selector:@selector(caseInsensitiveCompare:)];    
  
      NSArray *descriptors = [NSArray arrayWithObject:sortDescriptor];
      [fetchRequest setSortDescriptors:descriptors];
  
      // Recover query
      NSString *query = self.searchDisplayController.searchBar.text;
      //if (query &amp;&amp; query.length) fetchRequest.predicate = [NSPredicate predicateWithFormat:@"Term contains[cd] %@", query];
      if(searchValue==1)
      {
          if (query &amp;&amp; query.length) fetchRequest.predicate = [NSPredicate predicateWithFormat:@"name contains[cd] %@", query];
      }
      else {
          if (query &amp;&amp; query.length) fetchRequest.predicate = [NSPredicate predicateWithFormat:@"socialSecurity contains[cd] %@", query];
      }        
  
      // Init the fetched results controller
      NSError *error;
      self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"pLLetter" cacheName:nil];
  
      self.fetchedResultsController.delegate = self;
  
      if (![[self fetchedResultsController] performFetch:&amp;error]) NSLog(@"Error: %@", [error localizedDescription]);
  
      [self.tableView reloadData];
  }
  </code></pre>
  
  <p>I don't know how to put both properties into this statement...</p>
  
  <pre><code>if (query &amp;&amp; query.length) fetchRequest.predicate = [NSPredicate predicateWithFormat:@"name contains[cd] %@", query];
  </code></pre>
  
  <p>Any help or ideas would be greatly appreciated.</p>