I have a problem where I am inserting entities A in a context. Right after I insert all of the entities A I execute a fetch request on the context:
NSEntityDescription* entity = [NSEntityDescription entityForName:@"A" inManagedObjectContext:ctx];
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
NSError* fetchError;
NSArray* results = [ctx executeFetchRequest:fetchRequest error:&fetchError];
This code above is able to get all of them and I can see them in the NSLog...
Right after on the same context I try to fetch all entities A that have age = 5, like this: (I assign "age" to the attirbute and a NSString @"5" to the value)
NSEntityDescription* entity = [NSEntityDescription entityForName:@"A" inManagedObjectContext:ctx];
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"%K == %@",attr,value];
[fetchRequest setPredicate:filter];
NSError* fetchError;
NSArray* results = [ctx executeFetchRequest:fetchRequest error:&fetchError];
THE PROBLEM IS that even though the NSLog shows an entity A with age 5 this last fetch request returns always null! Nothing.
Any suggestions? Why fetching all of them shows entities with age 5 and filtering for age 5 only does not work right after on the same context?
Thanks