问题
I use this NSExpressionDescription to get the max value for the attribute date_modified:
NSFetchRequest *dateModifiedFR = [[NSFetchRequest alloc] initWithEntityName:@"MyEntity"];
dateModifiedFR.resultType = NSDictionaryResultType;
NSExpression *keyPathExpression = [NSExpression expressionForKeyPath:@"date_modified"];
NSExpression *maxDateExpression = [NSExpression expressionForFunction:@"max:" arguments:@[keyPathExpression]];
NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init];
[expressionDescription setName:@"maxDate"];
[expressionDescription setExpression:maxDateExpression];
[expressionDescription setExpressionResultType:NSDateAttributeType];
dateModifiedFR.propertiesToFetch = @[expressionDescription];
NSError *error = nil;
NSArray *resultDictionaries = [moc executeFetchRequest:dateModifiedFR error:&error];
NSDate *maxDate = [[resultDictionaries firstObject] valueForKey:@"maxDate"];
This works fine under iOS 7 as long as I use a SQLite store. But now I want to run this code with my unit tests using an in-memory store and executing this fetch request throws: 'NSInvalidArgumentException', reason: '-[__NSDate count]: unrecognized selector sent to instance 0xa01b410'
I know that there are other ways to get the max value in this case, but I'm curious what's wrong with this fetch request or why it can't run on the in-memory store.
回答1:
It looks like this is actually a bug. I've filed a radar with Apple.
来源:https://stackoverflow.com/questions/19301181/exception-raised-by-nsexpressiondescription-with-core-data-in-memory-store