cocoa - NSArrayController 获取与过滤谓词

标签 cocoa nsarraycontroller

我正在开发一个 Mac 应用程序,并且正在努力让谓词过滤器正常工作。对于 NSArrayController,使用 fetch 与过滤谓词的方式有什么不同吗?

我正在使用 Core Data 来存储我的记录,它们在我的表格 View 中完美显示。当我使用 fetch 谓词时,它会正确显示记录。当我使用过滤谓词时,它似乎没有做任何事情。需要明确的是 - 我一次使用一个谓词,但想在我的代码中显示这两个谓词。

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]);
}

最佳答案

看来关键字“deleted”对于Core Data来说有着某种未知的意义。我重命名了我的属性(property)并解决了问题。这篇博文也提到了同样的问题:http://roobasoft.com/blog/2006/04/25/secret-core-data-reserved-keywords/

关于cocoa - NSArrayController 获取与过滤谓词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7342048/

相关文章:

macos - 如何镜像 NSMutableArray?

objective-c - 根据按键更改 NSPopUpButton 项目的可见性

cocoa - NSArrayController:如何以编程方式清除选择?

ios - NSDecimalNumber 返回错误的 uint64_t 值

Objective-C 和 ASIHTTPRequest 返回值

ios - 转换为二进制 - long long 和 NSUInteger

cocoa - 使用字符串值填充 NSPopUpButtonCell

cocoa - 如何将 NSButton 启用状态绑定(bind)到组合条件

objective-c - NSArrayController 观察其内容计数

cocoa - 设置 Action 名称 : method purpose for NSUndoManager class