CoreData: How to fetch a specific object using a predicate

后端 未结 4 1214
不知归路
不知归路 2020-12-30 03:13

The situation:

I fetch a complete table from my sqllite core data database and show it in a TableView like this:

NSEntityDescriptio         


        
4条回答
  •  梦谈多话
    2020-12-30 03:40

    If you have an entry object called entry, it would be a predicate like this:

    NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(SELF = %@)", entry];
    

    Which is roughly equivalent to

    NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(objectID = %@)", entry.objectID];
    

    For a NSManagedObjectID, you get something like:

    NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(objectID = %@)", myEntryID];
    

提交回复
热议问题