情况:
我从我的 sqllite 核心数据数据库中获取一个完整的表,并将其显示在 TableView 中,如下所示:
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyTable"
inManagedObjectContext:managedObjectContext];
挑战:
如何获取 EntryID 并从数据库中获取特定条目(例如,如果我单击一个条目)?我认为这是正确的方向?
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(id = %@)", myEntryID];
最佳答案
如果你有一个名为 entry
的入口对象,它会是这样一个谓词:
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(SELF = %@)", entry];
大致相当于
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(objectID = %@)", entry.objectID];
对于 NSManagedObjectID
,您会得到如下内容:
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(objectID = %@)", myEntryID];
关于objective-c - 核心数据 : How to fetch a specific object using a predicate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2306137/