gpt4 book ai didi

ios - 核心数据 NSFetchRequest setResultType :NSDictionaryResultType not working

转载 作者:可可西里 更新时间:2023-11-01 04:23:03 25 4
gpt4 key购买 nike

当将 NSFetchRequest 结果类型设置为 NSDictinaryResultType 时,将返回零个对象。如果我删除 setPropertiesToFetch 和 setResultType,将返回所有对象。

有什么想法吗?

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]);
}

最佳答案

问题是我需要在插入新对象后保存 managedObjectContext。一旦我这样做了,我就得到了我正在寻找的结果。

关于ios - 核心数据 NSFetchRequest setResultType :NSDictionaryResultType not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7019422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com