The situation:
I fetch a complete table from my sqllite core data database and show it in a TableView like this:
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyTable"
inManagedObjectContext:managedObjectContext];
The Challenge:
How do I get the EntryID and fetch the specific entry from the database (e.g. if i click on an entry)? I think this goes in the right direction?
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(id = %@)", myEntryID];
For example, if you already completed project 33 you'll have seen how predicates let us find iCloud objects by reference. Put simply, a predicate is a filter: you specify the criteria you want to match, and Core Data will ensure that only matching objects get returned.
Fetched Properties in Core Data are properties that return an array value from a predicate. A fetched property predicate is a Core Data query that evaluates to an array of results.
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];
This is proper predicate:
[NSPredicate predicateWithFormat:@"SELF = %@", objectID];
Where objectID
is NSManagedObjectID
instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With