开发者

CoreData: Find minimum of calculated property

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开发者_StackOverflow社区 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜