Is there any way to use NSPredicate to filter objects using distance calculation between points in CoreData

↘锁芯ラ 提交于 2019-12-12 20:31:37

问题


For example I have NSManagedObject with x and y double values. I want to get list of point that are located on some distance from provided one. I tried to use next predicate:

[NSPredicate predicateWithFormat:@"(x-%f)(x-%f)-(y-%f)(y-%f) <= %f", point.x, point.x, point.y, point.y, 25*25] . But it doesn't work for some reason :(( .

In my experiments I found out that predicate like (x-1)*2-x >= 0 returns 0 objects even if x is greater than 1, and (x+1)*2-x >= 0 returns all objects. So I suspect that calculations in predicate is not supported, but there are no information about it anywhere I looked

来源:https://stackoverflow.com/questions/13141615/is-there-any-way-to-use-nspredicate-to-filter-objects-using-distance-calculation

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