CoreData:找到计算属性的最小值

发布于 2024-08-09 03:18:12 字数 241 浏览 10 评论 0原文

假设我有一个 CoreData 实体“Point”,具有两个属性 x 和 y(均为 NSNumber)。

NSPredicate 需要是什么样子才能让我找到最接近 a、b 的点? for distance = sqrt((xa)(xa)+(yb)(yb))

虽然我可以定义一个瞬态属性来计算到预定义点的距离,但我不知道如何以编程方式在启动 fetchrequest 时更改该点。

任何帮助将不胜感激。

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

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))

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.

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魂归处 2024-08-16 03:18:12

抱歉,不支持在 NSPredicate 中进行算术运算。只能使用比较运算符。消息变得更糟。您不能在 NSFetchRequest 中使用瞬态属性。只能使用持久属性。如果您确实需要这种级别的控制来获取对象,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文