我的获取请求是获取所有组对象,而不是我想要的。
我希望它只获取当前用户所属的组,但我的谓词似乎不起作用。有什么想法吗?
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"AGroup" inManagedObjectContext:_managedObjectContext]];
AUser *u = [AUser currentUser]; //gets app's current user
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"ANY users = %@", u]];
我也尝试了以下方法,但没有奏效:
[NSPredicate predicateWithFormat:@"(users CONTAINS %@)", u];
[NSPredicate predicateWithFormat:@"SUBQUERY(users, $user, $user = %@).@count = [users count]", u];
类结构
AGroup
- users (Type: AUser *)
AUser
- name (Type: NSString *)