带有Core Data内存存储的NSExpressionDescription引发的异常 [英] Exception raised by NSExpressionDescription with Core Data in-memory store

查看:161
本文介绍了带有Core Data内存存储的NSExpressionDescription引发的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此NSExpressionDescription获取属性date_modified的最大值:

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"];

只要我使用SQLite商店,这在iOS 7下运行正常。但现在我想使用内存存储运行我的单元测试并执行此获取请求抛出此代码:'NSInvalidArgumentException',原因:' - [__ NSDate count]:无法识别的选择器发送到实例0xa01b410 '

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.

推荐答案

看起来这实际上是一个错误。我已经向Apple提交了雷达。

It looks like this is actually a bug. I've filed a radar with Apple.

这篇关于带有Core Data内存存储的NSExpressionDescription引发的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆