Sunday, November 3, 2013

floating point comparisons in CoreData fetch requests

I had to use a predicate like this in order to compare a test value to another one in my predicate so that things were working good.

[NSPredicate predicateWithFormat:@"abs(value - %f) < 0.01", test];

Here was the question I asked:

I guess it turns out you can use SQLIte functions like abs() and cetera for more shit. Yay woo. I was led to this because the BETWEEN function doesn't work with floats, but crashes. You get the "unrecognized selector nsnumber" type error.

See also:

Predicate Programming Guide

Getting Stuck

Predicate Format String Syntax

Creating Predicates

No comments:

Post a Comment