1

2 つのモデル クラス

AUser
- name

AGroup
- users 

グループとユーザーは、多対多の関係を共有します。

2 つのセットがまったく同じユーザーを共有しているかどうか (ユーザーが多いか少ないかではなく) を確認したい

しかし残念ながら、次のエラーが表示されます: to-many key not allowed here

私は他のSOの質問を見てきましたが、過去2時間彼らの方法論を使用しようとしたため、どれも当てはまらなかったことに注意してください。または、少なくとも私はそれらをよく理解していませんでした。

また、2 つの変更可能なセットを比較するための述語は大丈夫ですか?

- (BOOL)conversationExists:(NSMutableSet *)members {
    NSFetchRequest *request= [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"AGroup" inManagedObjectContext:_managedObjectContext];
    NSPredicate *predicate =[NSPredicate predicateWithFormat:@"users==%@",members]; 
    //There is more code that I have not shown here as it is irrelevant to the question
    //Mainly The NSPredicate line is the problem
}

お時間をいただきありがとうございました。ほんとうにありがとう。

から、 新しい iOS プログラマー

4

2 に答える 2

2

この投稿には答えがありました: How to use the "ALL" aggregate operation in a NSPredicate to filter a CoreData-based collection

基本的に次のようなものです:

[NSPredicate predicateWithFormat:@"SUBQUERY(members, $member, $member IN %@).@count = %d", members, [members count]];
于 2013-03-07T02:11:45.620 に答える
2

なぜ述語である必要があるのですか?

何が問題なの[[groups valueForKey:@"users"] isEqualToSet:members]ですか?

于 2013-03-07T06:22:16.110 に答える