cocoa – 核心数据:试图找到实体中属性的最小日期

cocoa – 核心数据:试图找到实体中属性的最小日期,第1张

概述我正在尝试在Core Data中找到特定属性中最早的日期.我发现 an example in the Core Data Programming Guide声称可以做到这一点,但是当我运行它时仍然会收到一个无法识别的选定错误. 我的代码(只有Apple示例中的最小更改): NSFetchRequest *request = [[NSFetchRequest alloc] init];NSEnti 我正在尝试在Core Data中找到特定属性中最早的日期.我发现 an example in the Core Data Programming Guide声称可以做到这一点,但是当我运行它时仍然会收到一个无法识别的选定错误. @H_301_7@

@H_301_7@我的代码(只有Apple示例中的最小更改):

@H_301_7@

NSFetchRequest *request = [[NSFetchRequest alloc] init];NSEntityDescription *entity = [NSEntityDescription entityForname:@"Session" inManagedobjectContext: ctx];[request setEntity:entity];// Specify that the request should return dictionarIEs.[request setResultType:NSDictionaryResultType];// Create an Expression for the key path.NSExpression *keyPathExpression = [NSExpression ExpressionForKeyPath:@"startedAt"];// Create an Expression to represent the minimum value at the key path 'creationDate'NSExpression *minExpression = [NSExpression ExpressionForFunction:@"min:" arguments:[NSArray arrayWithObject:keyPathExpression]];// Create an Expression description using the minExpression and returning a date.NSExpressionDescription *ExpressionDescription = [[NSExpressionDescription alloc] init];// The name is the key that will be used in the dictionary for the return value.[ExpressionDescription setname:@"minDate"];[ExpressionDescription setExpression:minExpression];[ExpressionDescription setExpressionResultType:NSDateAttributeType];// Set the request's propertIEs to fetch just the property represented by the Expressions.[request setPropertIEsToFetch:[NSArray arrayWithObject:ExpressionDescription]];// Execute the fetch.NSError *error;NSArray *objects = [ctx executeFetchRequest:request error:&error];
@H_301_7@而错误:

@H_301_7@

-[NSCalendarDate count]: unrecognized selector sent to instance ...
@H_301_7@鉴于1)NSCalendarDate已弃用且2)我绝对不会调用count,这很奇怪.

@H_301_7@非常感激任何的帮助!

解决方法 为什么不添加一个排序描述符来按beginDate升序排序,然后只让fetch请求返回1个对象? 总结

以上是内存溢出为你收集整理的cocoa – 核心数据:试图找到实体中属性的最小日期全部内容,希望文章能够帮你解决cocoa – 核心数据:试图找到实体中属性的最小日期所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1020599.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存