0

我有一个实体和三个属性,称为项目、费率、类别。我想从类别属性中过滤值。

    if (managedObjectContext==nil) {
        AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        managedObjectContext = appDelegate.managedObjectContext;

    }

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Restaurantmenu" inManagedObjectContext:managedObjectContext];
    [request setEntity:entity];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"('category' contains[c] 'Fast Foood')"];
[request setPredicate:predicate];
NSLog(@"Pre %@",predicate);
    NSError *error = nil;
    NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
    if (mutableFetchResults == nil) {
        // Handle the error.
    }

    // Set self's events array to the mutable array, then clean up.
    [self setDataarr:mutableFetchResults];

但我不能这样做请帮助我。

4

1 回答 1

0

从下面的代码中替换您的谓词初始化并尝试

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category CONTAINS[c] %@", @"Fast Foood"]; 
于 2013-02-27T14:03:30.303 回答