Это буквально сводит меня с ума.
У меня есть 2 объекта, которые используют NSStrings как уникальный атрибут.
Как правильно создать предикат для сравнения строк NSString?
В настоящее время у меня есть: [NSPredicate predicateWithFormat:@"unique= %@", uniqueValue];
Мне кажется, что здесь сравниваются адреса указателей, а не фактические строковые значения, но я не могу этого подтвердить. Мне нужно вернуть да для точного совпадения строки.
-(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:&error];
if (!matches)
{
NSLog(@"Error: no object matches");
}
else if([matches count] > 1) {
NSLog(@"Error: More than one object for unique record");
returnValue = YES;
} else if ([matches count] == 0) {
returnValue = NO;
} else {
returnValue = YES;
}
return returnValue;
}