gpt4 book ai didi

ios - 无法从核心数据中获取不同的属性值

转载 作者:行者123 更新时间:2023-11-28 22:32:25 25 4
gpt4 key购买 nike

下面有 2 个函数,但只有一个有结果。在“noResult”中,我试图获取不同属性值的列表,但我得到的只是 {}。

-(void)noResult {
NSManagedObjectContext *moc= [xmppMessageArchivingStorage mainThreadManagedObjectContext];
NSEntityDescription *entity= [NSEntityDescription entityForName:@"XMPPMessageArchiving_Message_CoreDataObject" inManagedObjectContext:moc];
NSFetchRequest *request= [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setResultType:NSDictionaryResultType];
[request setReturnsDistinctResults:YES];
[request setPropertiesToFetch:[NSArray arrayWithObject:@"contact"]];

NSArray *messages= [moc executeFetchRequest:request error:nil];
NSLog(@"%@", messages);
}

-(void)gotResult {
NSManagedObjectContext *moc= [xmppMessageArchivingStorage mainThreadManagedObjectContext];
NSEntityDescription *entity= [NSEntityDescription entityForName:@"XMPPMessageArchiving_Message_CoreDataObject" inManagedObjectContext:moc];
NSFetchRequest *request= [[NSFetchRequest alloc] init];
[request setEntity:entity];
NSArray *messages= [moc executeFetchRequest:request error:nil];
}

以下来自“gotResult”"(entity: XMPPMessageArchiving_Message_CoreDataObject; id: 0x1c5d7fc0 ; data: {\n bareJid = nil;\n bareJidStr = nil;\n body =\"Bean bags\";\n composing = 0;\n contact = 1000743469142;\n from = 7375011;\n message = nil;\n messageStr = nil;\n outgoing = 0;\n streamBareJidStr = nil;\n thread = nil;\n timestamp =\"2013-06-05 10:56:38 +0000\";\n})"

最佳答案

我能做出不同行为的唯一原因想到的是您在调用使用 NSDictionaryResultType 获取请求。

[request setResultType:NSDictionaryResultType];

暗示

[request setIncludesPendingChanges:NO];

这意味着从获取中返回的数组反射(reflect)了持久存储中的当前状态,并且不考虑上下文中任何未决的更改、插入或删除。

关于ios - 无法从核心数据中获取不同的属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17019334/

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