【发布时间】:2013-12-26 16:57:55
【问题描述】:
在我的应用程序中,我有两个实体:成员和列表。它们都有一对多的关系(成员可以有多个列表,列表可以有多个成员)。现在我想获取属于特定成员的列表。这是我的代码:
WSAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Lists" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"has_members contains[cd] %@", [self.currentMember valueForKey:@"name"]]];
[fetchRequest setPredicate:predicate];
NSError *error;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
if (fetchedObjects == nil) {
// Handle the error.
NSLog(@"NO LISTS AVAILABLE IN REFRESH");
}
self.currentMember 是用户自己的托管对象。
注意:成员有名字,(NSSet*) member_of_list
list 有 list_name, has-members
问题:当我运行代码时,它在 fetchedObjects 数组中中断。我怀疑 NSPredicate 有问题,但我不知道在哪里以及如何修复它。谁能指出问题所在?
【问题讨论】:
-
您希望所有记录都针对某个记录...