在谓词中使用@min

编程入门 行业动态 更新时间:2024-10-11 23:22:36
本文介绍了在谓词中使用@min的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我当前获取@min或@max值的版本是:

My current version for get @min or @max value is:

for (NSManagedObject *destination in allSpecifics) { [allRates addObject:[destination valueForKey:@"rate"]]; } NSExpression *arrayExpression = [NSExpression expressionForConstantValue: allRates]; NSArray *argumentArray = [NSArray arrayWithObject: arrayExpression]; NSExpression* expression = [NSExpression expressionForFunction:@"min:" arguments:argumentArray]; id result = [expression expressionValueWithObject: nil context: nil]; NSNumber *rateForAdd = result;

allSpecific是NSManagedObjects的数组.看起来这不是一种填充对象数组的好方法(内存和处理时间成本).也许有人可以帮助重构它?

allSpecific is array of NSManagedObjects. Looks like is a not good way to fill array of objects before (memory and process time cost). Probably somebody can help refactor it?

推荐答案

因此,您有一个 NSManagedObjects 的数组( allSpecifics ),并且这些对象都有一个率属性?如果正确,那么:

So you have an array (allSpecifics) of NSManagedObjects, and these objects have a rate property? If that's correct then:

要查找:

  • 最低费率值: NSNumber * minimumRate = [allSpecifics valueForKeyPath:@"@ min.rate"];
  • 最大速率值: NSNumber * minimumRate = [allSpecifics valueForKeyPath:@"@ max.rate"];
  • 平均费率值: NSNumber * minimumRate = [allSpecifics valueForKeyPath:@"@ avg.rate"];
  • 总费率值: NSNumber * minimumRate = [allSpecifics valueForKeyPath:@"@ sum.rate"];

更多推荐

在谓词中使用@min

本文发布于:2023-11-30 14:38:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650354.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:谓词   min

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!