2011-06-23 38 views
2

我有一個具有.localConcerts提取屬性的藝術家對象(基本上是完整集合的一個子集,concerts集合),我可以在我的NSFetchedResultsController謂詞中使用該屬性嗎?NSFetchedResultsController謂詞中的提取屬性

這裏就是我想:

NSFetchRequest *request = [[NSFetchRequest alloc] init]; 

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Artist" inManagedObjectContext:context]; 
[request setEntity:entity]; 

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"[email protected] > 0"]; 
[request setPredicate:predicate]; 

fetchedResultsController = [[NSFetchedResultsController alloc] 
          initWithFetchRequest:request 
          managedObjectContext:context 
          sectionNameKeyPath:nil 
          cacheName:nil]; 

但我發現了:

'keypath localConcerts not found in entity <NSSQLEntity Artist id=1>' 

我缺少的東西,或只是不能使用內部謂詞獲取屬性?

回答

6

顯然NSPredicate只能使用數據庫結構中的屬性進行過濾(這很有意義)。在我的情況下,使用子查詢的伎倆:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(shows, $show, $show.distance < %@)[email protected] > 0", [SWDataManager sharedManager].localFilterDistance]; 

我不知道我們能做到subqueries in NSPredicate,這是偉大的知道。積分轉到@kyleve

相關問題