开发者

NSArrayController fetch vs filter predicate

I'm working on a Mac app and am struggling to get a predicate filter to work. Is there a difference in how you should use the fetch vs filter predicates for an NSArrayController?

I'm using Core Data to store my records and they display perfectly in my table view. W开发者_JS百科hen I use the fetch predicate it properly displays the records. When I use the filter predicate it does not seem to do anything. Just to be clear - I'm using one predicate at a time but wanted to show both in my code.

entryController = [[NSArrayController alloc] init];
[entryController setManagedObjectContext:[self managedObjectContext]];
[entryController setAutomaticallyPreparesContent:YES];
[entryController setAutomaticallyRearrangesObjects:YES];
[entryController setClearsFilterPredicateOnInsertion:NO];
[entryController setEntityName:@"Entry"];

// only displays entries where deleted is not 1
[entryController setFetchPredicate:[NSPredicate predicateWithFormat:@"deleted != %@", [NSNumber numberWithInt:1]]];

// shows all entries regardless of the deleted status
[entryController setFilterPredicate:[NSPredicate predicateWithFormat:@"deleted != %@", [NSNumber numberWithInt:1]]];

if ([entryController fetchWithRequest:nil merge:YES error:&error] == NO) {
    DLog(@"Error fetching entries: %@", error.description);
} else {
    DLog(@"Found %lu entries.", [[entryController arrangedObjects] count]);
}


It seems that the keyword "deleted" has some unknown significance to Core Data. I renamed my property and it resolved the issue. This blog post also mentions the same issue: http://roobasoft.com/blog/2006/04/25/secret-core-data-reserved-keywords/


From what I understand fetchPredicate is performed at the store level and filteringPredicate is performed in memory after the objects have already been retrieved.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜