【发布时间】:2011-08-25 15:59:30
【问题描述】:
我不确定如何将多个条件“级联”到一个 NSPredicate 中。
我对 Core Data 还很陌生,不确定这是否是实现我想要做的事情的正确方法。
这是我想要做的:
有一个 Photo 对象与 Location 对象具有 whereTook 关系,而 Location 对象具有 photosTookThere 的倒数。
照片又具有一个名为 isFavourite 的 NSNumber 属性。
我想配置一个 NSFetchRequest,它首先检查 photosTookThere 是否存在,如果存在,则检查每个生成的 Photo 对象并仅返回设置为收藏夹的对象。
这是目前为止的代码:
request.entity = [NSEntityDescription entityForName:@"Location" inManagedObjectContext:context];
request.sortDescriptors = [NSArray arrayWithObject[NSSortDescriptorsortDescriptorWithKey:@"locationId" ascending:YES]];
request.predicate = [NSPredicate predicateWithFormat:@"photosTookThere.@count != 0"];
如何将第二个条件级联到谓词中并返回正确的结果?
【问题讨论】:
标签: iphone objective-c xcode ios core-data