Can someone help me define a predicate that only NSManagedObject returns, the length of the “letter” attribute is within a certain range?
Here is an example that I tried, I have the feeling that it is the letter letter.length, I also tried the letters kvc. @ length without success .. What am I doing wrong?
NSManagedObjectContext *context = ...; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Word" inManagedObjectContext:context]; [fetchRequest setEntity:entity]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"letters" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"letters.length BETWEEN %@", [NSArray arrayWithObjects: [NSNumber numberWithInt:5], [NSNumber numberWithInt:20], nil]]; [fetchRequest setPredicate:predicate]; NSUInteger limit = 20; [fetchRequest setFetchLimit:limit]; NSError *error = nil; NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
nsstring core-data nsmanagedobject nspredicate
jbg Sep 05 '10 at 1:20 2010-09-05 01:20
source share