开发者

Core Data NSFetchRequest setResultType:NSDictionaryResultType not working

开发者 https://www.devze.com 2023-03-27 11:02 出处:网络
When setting a NSFetchRequest result type to NSDictinaryResultType, zero objects are returned.If I remove setPropertiesToFetch and setResultType, all the objects are returned.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消