CoreData:查找计算属性的最小值 [英] CoreData: Find minimum of calculated property

查看:287
本文介绍了CoreData:查找计算属性的最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个CoreData实体Point,有两个属性x和y(都是NSNumber)。

Say I have a CoreData entity "Point" with two properties x and y (both NSNumber).

NSPredicate如何看起来像是让我找到最近的点说a,b?
for distance = sqrt((xa)(xa)+(yb)

How would a NSPredicate need to look like to let me find the closest Point to say a,b? for distance = sqrt((x-a)(x-a)+(y-b)(y-b))

transient属性计算到一个预定义点的距离我不能看到我如何可以在启动fetchrequest时以编程方式更改该点。

While I could define a transient property that calculates a distance to a predefined point I can't see how I could programmatically change that point when launching a fetchrequest.

任何帮助将非常感激。

推荐答案

不支持在 NSPredicate 中执行算术。只能使用比较运算符。新闻越来越糟。您不能在 NSFetchRequest 中使用transient属性。只能使用持久属性。如果你在获取对象时真的需要这个级别的控制,Core Data可能无法满足你的需要。

Sorry, but doing arithmetic in an NSPredicate isn't supported. Only comparison operators can be used. And the news gets worse. You can't use a transient property in an NSFetchRequest. Only persistent properties can be used. If you really need this level of control in fetching your objects, Core Data may not be able to accommodate you.

这篇关于CoreData:查找计算属性的最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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