CoreData: Find minimum of calculated property

China☆狼群 提交于 2019-12-04 08:47:14

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/1625187/coredata-find-minimum-of-calculated-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!