我有一個many-to-many
與兩個實體的關係。一個是Person
,另一個是Clubs
。我希望能夠編寫一個predicate
,它將查找特定Club
中的所有Person
實體。我也想檢查那個人的position
屬性。NSPredicate按屬性篩選核心數據關係NSSet
這裏是不工作:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Person" inManagedObjectContext:self.managedObjectContext]];
[request setPredicate:[NSPredicate predicateWithFormat:@"position CONTAINS[cd] %@ AND IN %@", @"manager", self.clubs.people]];
NSArray *results = [self.managedObjectContext executeFetchRequest:request error:nil];
這崩潰,出現錯誤:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "title CONTAINS[cd] %@ AND IN %@"'
我知道我錯在這裏做的事情,任何幫助嗎?
嘗試使用自指Person對象本身,而不是一個屬性更高效:'[NSPredicate predicateWithFormat:@「的位置包含:[CD]% @ AND SELF IN%@「,@」manager「,self.clubs.people]' – pbasdf