Comparison Predicates

Comparison Predicates_第1张图片Comparison Predicates_第2张图片


Comparison Predicates_第3张图片

例子:

NSManagedObjectContext *context = [self managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person"➥
inManagedObjectContext:context];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
NSExpression *exprName = [NSExpression expressionForKeyPath:@"name"];
NSExpression *exprJane = [NSExpression expressionForConstantValue:@"Jane"];
NSPredicate *predicate = [NSComparisonPredicate predicateWithLeftExpression:exprName➥
rightExpression:exprJane modifier:NSDirectPredicateModifier➥
type:NSEqualToPredicateOperatorType options:0];
[fetchRequest setPredicate:predicate];
NSArray *persons = [context executeFetchRequest:fetchRequest error:nil];
for(NSManagedObject *person in persons) {
NSLog(@"name=%@ age=%@", [person valueForKey:@"name"], [person valueForKey:@"age"]);
}
[fetchRequest release];


你可能感兴趣的:(Comparison Predicates)