Exception raised by NSExpressionDescription with Core Data in-memory store

帅比萌擦擦* 提交于 2019-12-06 14:03:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!