NSDictionaryResultType表达式未考虑新插入的对象

Mic*_*all 5 core-data nsfetchrequest

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

// 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];
}
Run Code Online (Sandbox Code Playgroud)

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

我在文档中找不到任何引用.

谢谢,

麦克风

Mic*_*all 7

我收到了Apple开发者论坛的回复,并确认它没有考虑未保存的更改.