Mikayil Abdullayev
Mikayil Abdullayev

Reputation: 12367

How do I use NSExpression with NSPredicate

I searched the whole internet but could not find any good explanation on how to use NSExpression in NSPredicate. I know that there's built in function abs which I need for my predicate. I have this predicate:

NSPredicate *predicate=[NSPredicate predicateWithFormat:@"hg-%f<0.000001",[txtInput.text floatValue]];

I need absolute value of hg-[txtInput.text floatValue] part. How do I achieve it?

Upvotes: 0

Views: 1923

Answers (1)

David R&#246;nnqvist
David R&#246;nnqvist

Reputation: 56625

Add abs( ) around the expression you want the absolute value of inside your predicate string

NSPredicate *predicate=[NSPredicate predicateWithFormat:@"abs(hg-%f)<0.000001",[txtInput.text floatValue]];

Upvotes: 4

Related Questions