title: NSPredicate Returns No Results with Fetch Request, Works with Array Filtering
body: <p>My situation is simple: I have some records in my core data store. One of their attributes is a string called "localId". There's a point where I'd like to find the record with a particular localId value. The obvious way to do this is with an NSFetchRequest and an NSPredicate. However, when I set this up, the request returns zero records.</p>
  
  <p>If, however, I use the fetch request without the predicate, returning all records, and just loop over them looking for the target localId value, I do find the record I'm looking for. In other words, the record is there, but the fetch request can't find it.</p>
  
  <p>My other methods in which I use fetch requests and predicates are all working as expected. I don't know why this one is failing.</p>
  
  <p>I want to do this:</p>
  
  <pre><code>- (void)deleteResultWithLocalID:(NSString *)localId {
      NSFetchRequest *request = [[NSFetchRequest alloc] init];
      [request setEntity:[NSEntityDescription entityForName:@"WCAAssessmentResult" inManagedObjectContext:context]];
      [request setPredicate:[NSPredicate predicateWithFormat:@"localId == %@", localId]];
      NSError *error = nil;
      NSArray *results = [context executeFetchRequest:request error:&amp;error];
      NSAssert(error == nil, ([NSString stringWithFormat:@"Error: %@", error]));
      if ([results count]) [context deleteObject:[results objectAtIndex:0]];
      else NSLog(@"could not find record with localID %@", localId);
      [self saveContext];
  }
  </code></pre>
  
  <p>But I end up having to do this:</p>
  
  <pre><code>- (void)deleteResultWithLocalID:(NSString *)localId {
      NSFetchRequest *request = [[NSFetchRequest alloc] init];
      [request setEntity:[NSEntityDescription entityForName:@"WCAAssessmentResult" inManagedObjectContext:context]];
      NSError *error = nil;
      NSArray *results = [context executeFetchRequest:request error:&amp;error];
      NSAssert(error == nil, ([NSString stringWithFormat:@"Error: %@", error]));
      for (WCAAssessmentResult *result in results) {
          if ([result.localId isEqualToString:localId]) {
              NSLog(@"result found, deleted");
              [context deleteObject:result];
          }
      }
      [self saveContext];
  }
  </code></pre>
  
  <p>Any clues as to what could be going wrong?</p>
  
  <p><strong>edit</strong></p>
  
  <p>I've found that I can use the predicate I'm creating to get the results I expect after the fetch request has been executed. So, the following also works:</p>
  
  <pre><code>- (WCAChecklistItem *)checklistItemWithId:(NSNumber *)itemId {
       NSFetchRequest *request = [[NSFetchRequest alloc] init];
       [request setEntity:[NSEntityDescription entityForName:@"WCAChecklistItem" inManagedObjectContext:context]];
       NSArray *foundRecords = [context executeFetchRequest:request error:nil];
       foundRecords = [foundRecords filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"serverId == %@", itemId]];
       if ([foundRecords count]) {
           return [foundRecords objectAtIndex:0];
       } else {
           NSLog(@"can't find checklist item with id %@", itemId);
           return nil;
      }
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I've come across someone else experiencing this very issue:</p>
  
  <p><a href="http://markmail.org/message/7zbcxlaqcgtttqo4">http://markmail.org/message/7zbcxlaqcgtttqo4</a></p>
  
  <p>He hasn't found a solution either.</p>
  
  <p>Blimey! I'm stumped.</p>
  
  <p>Thanks!</p>