我的對象圖看起來像這樣核心數據與一對多的關係 - 在SUBQUERY創建一個NSPredicate與ALL
快照 - >>面板 - > ManagedImage
我試圖找到一個快照具有確切的ManagedImages包含在一個集合中。
我現在得到的代碼返回一組具有一組或多組ManagedImages的SnapShots。然後我搜索數組以找到正確的SnapShot,但我猜測在子查詢中過濾要快得多
使用NSPredicate如何獲取具有所有ManagedImages的獨特SnapShot組?
這裏是我的代碼
mySet = ... // A unique set of (usually 3) managedImages that I'm trying to find a snapShot for
NSFetchRequest *request = ...
request.entity = [NSEntityDescription entityForName:@"SnapShot" inManagedObjectContext:[self managedObjectContext]];
// Want this to work but sends an exception
//request.predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(self.panes, $pane, ALL $pane.managedImage IN %@)[email protected] != 0", mySet];
// Using this
request.predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(self.panes, $pane, $pane.managedImage IN %@)[email protected] != 0", mySet];