Reputation: 694
I would like to get the id of some data stored in Core data... This is to check if some value exist already inside the database.. If it exist, it shows something if not else.
The id always changes because I get it in the last view from the push. So if the ID exist in the database, I want to detect it.
Upvotes: 0
Views: 1054
Reputation: 6710
I think you asking about querying in Core Data. Here is a basic example:
NSString *testEntityId = @"555";
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
fetch.entity = [NSEntityDescription entityForName:@"YourEntity" inManagedObjectContext:moc];
fetch.predicate = [NSPredicate predicateWithFormat:@"entityId == %@", testEntityId];
NSArray *array = [moc executeFetchRequest:fetch error:nil];
You'll get an array of items that match.
Upvotes: 2
Reputation: 1377
You can compare object directly with a
[Object isEqualsTo:secondObject]
Otherwise, you can create a integer inside your core data with a field name like "GUID" or other name and verify that integer doesn't exist for each adding...
Good luck ;)
Upvotes: 0