使用NSPredicate如何使用1个实体从核心数据中过滤值 [英] Using NSPredicate how to filter value from core data using 1 entity

查看:65
本文介绍了使用NSPredicate如何使用1个实体从核心数据中过滤值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have one entity & three Attribute called as item, rate, category. i want to filter value from category attribute.

    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];

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

but i cant do this plz help me.

推荐答案

从下面的代码中替换谓词的初始化,然后尝试

Replace your initialization of predicate from the code below and try

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category CONTAINS[c] %@", @"Fast Foood"]; 

这篇关于使用NSPredicate如何使用1个实体从核心数据中过滤值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆