When setting a NSFetchRequest result type to NSDictinaryResultType, zero objects are returned. If I remove setPropertiesToFetch and setResultType, all the objects are returned.
Any ideas?
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Alert" inManagedObjectContext:_managedObjectContext];
[request setEntity:entity];
NSDictionary *entityProperties = [entity propertiesByName];
[request setPropertiesToFetch:[NSArray arrayWithObject:[entityProperties objectForKey:@"test"]]];
[request setResultType:NSDictionaryResultType];
NSError *error;
NSArray *result = [_managedObjectContext executeFetchRequest:request error:&error];
if (result == nil) {
NSLog(@"Error: %@", [error localizedDescription]);
}
The problem was I needed to save the mangedObjectContext after inserting new objects. Once I did that I get the results I was looking for.
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