title: iOS Core Data how to properly compare string text using predicates?
body: <p>This is literally driving me nuts. </p>
  
  <p>I have 2 entities that use NSStrings as unique attribute. </p>
  
  <p>What is the correct way to create a predicate that compares NSStrings?</p>
  
  <p>Currently I have:
      [NSPredicate predicateWithFormat:@"unique= %@", uniqueValue];</p>
  
  <p>I have a feeling that this compares the pointer addresses, not actual string values, but I cannot confirm that. I need to return yes for an exact string match. </p>
  
  <pre><code>-(BOOL)uniqueEntityExistsWithEnityName:(NSString*)entityName UniqueKey:(NSString*) uniqueKey UniqueValue:(NSString*)uniqueValue SortAttribute:(NSString*)sortDescriptorAttribute ManagedObjectContext:(NSManagedObjectContext*) context;
  {
      BOOL returnValue = NO;
  
      NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];
  
  //what is the correct predates to compare the text an string core data property against a passed in string?
      request.predicate = [NSPredicate predicateWithFormat:@"unique= %@", uniqueValue];
  
      NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:sortDescriptorAttribute ascending:YES];
      request.sortDescriptors = [NSArray arrayWithObject:sortDescriptor];   
  
      NSError *error = nil;
      NSArray *matches = [context executeFetchRequest:request error:&amp;error];
      if (!matches)
      {
           NSLog(@"Error: no object matches");
      }
      else if([matches count] &gt; 1) {
          NSLog(@"Error: More than one object for unique record");
          returnValue = YES;
  
      } else if ([matches count] == 0) {
          returnValue = NO;
      } else {
          returnValue = YES;
      }
  
      return returnValue;
  }
  </code></pre>