【问题标题】:How to correctly setup a NSPredicate for a to-many relationship, to check existance object如何为一对多关系正确设置 NSPredicate 以检查存在对象
【发布时间】:2014-09-11 12:55:44
【问题描述】:

我有两个表 TRIP 和 ALERT

关系是一对多 一次行程可以包含 1 个或多个警报, 我想获取那些包含警报的行程

我提出这样的获取请求,请资产我亲爱的

-(NSFetchRequest*) fetchRequestGetTriphaveAlert{ NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];

NSEntityDescription *trip = [NSEntityDescription entityForName:@"Trip" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:trip];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"alert == %@",!NULL];
[fetchRequest setPredicate:predicate];
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"startDate" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
return fetchRequest;

}

【问题讨论】:

    标签: ios objective-c iphone core-data


    【解决方案1】:

    试试这个:

    NSPrediate *predicate = [NSPredicate predicateWithFormat:@"alert.@count > 0"];
    

    【讨论】:

      猜你喜欢
      • 2010-11-23
      • 1970-01-01
      • 2014-09-08
      • 2015-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-27
      • 1970-01-01
      相关资源
      最近更新 更多