亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我有兩個類,ClassA和ClassB,關系如下:

我有兩個類,ClassA和ClassB,關系如下:

iOS
千萬里不及你 2023-04-15 22:18:31
我需要查詢所有count>10的ClassA的bObjects中name為hello的ClassB的對象。請問能不能用一個NSPredicate來表示這個查詢?
查看完整描述

2 回答

?
精慕HU

TA貢獻1845條經驗 獲得超8個贊

看了蘋果的文檔,里面寫的例子:

If you use a to-many relationship, the construction of a predicate is slightly different. If you want to fetch Departments in which at least one of the employees has the first name "Matthew," for instance, you use an ANY operator as shown in the following example:
 NSPredicate *predicate = [NSPredicate predicateWithFormat:    @"ANY employees.firstName like 'Matthew'"];

所以,我覺得查詢應該是:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(name = %@) AND (ANY aObjects.count > 10)", @"hello"];


查看完整回答
反對 回復 2023-04-19
?
阿波羅的戰車

TA貢獻1862條經驗 獲得超6個贊

腦補的,沒測試。不好用請更正我

NSEntityDescription *entity = [NSEntityDescription
                                   entityForName:@"ClassB"
                                   inManagedObjectContext:context];NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(name = %@) AND (aObjects.count > 10)", @"hello"];
[fetchRequest setPredicate:predicate];


查看完整回答
反對 回復 2023-04-19
  • 2 回答
  • 0 關注
  • 158 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號