gpt4 book ai didi

core-data - NSDictionaryResultType 表达式不考虑新插入的对象

转载 作者:行者123 更新时间:2023-12-03 14:05:58 24 4
gpt4 key购买 nike

我想要核心数据中某个字段的最大值,因此我设置了以下请求:

// Create fetch
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
[fetch setEntity:[NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:context]];
[fetch setResultType:NSDictionaryResultType];

// Expression for Max ID
NSExpression *keyPathExpression = [NSExpression expressionForKeyPath:@"myNumbericID"];
NSExpression *minExpression = [NSExpression expressionForFunction:@"max:" arguments:[NSArray arrayWithObject:keyPathExpression]];
NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init];
[expressionDescription setName:@"maxID"];
[expressionDescription setExpression:minExpression];
[expressionDescription setExpressionResultType:NSDoubleAttributeType];
[fetch setPropertiesToFetch:[NSArray arrayWithObject:expressionDescription]];

// Execute the fetch.
double theID = 0;
NSError *error;
NSArray *objects = [context executeFetchRequest:fetch error:&error];
if (objects && [objects count] > 0) {
theID = [((NSNumber *)[[objects objectAtIndex:0] valueForKey:@"maxID"]) doubleValue];
}

但是,它似乎没有考虑事先插入上下文中的任何新对象。这是它应该如何工作?它仅适用于商店中的元素吗?

我在文档中找不到任何对它的引用。

谢谢,

麦克风

最佳答案

我收到了来自 Apple Developer Forums 的回复,并确认它没有考虑未保存的更改。

关于core-data - NSDictionaryResultType 表达式不考虑新插入的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1632029/

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