NSFetchRequest setResultType master data: NSDictionaryResultType not working

Setting the result type of NSFetchRequest to NSDictinaryResultType returns null objects. If I delete setPropertiesToFetch and setResultType, all objects will be 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]);
}
+5
source share
1 answer

The problem was that I needed to save mangedObjectContext after inserting new objects. As soon as I did this, I got the results that I was looking for.

+10
source

All Articles