How to filter the array using NSPredicate so that the value of one property is greater than others?

advertisements

I have an array of objects which two properties X and Y (both NSString). I want to filter the array using predicate such that all the filtered objects have X > Y. Currently, I am using:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(X > Y"];

My program crashes at this line. What is the correct way of writing this predicate?


NSPredicate *predicate = [NSPredicate predicateWithFormat:@"X > Y"];

or

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(X > Y)"];

should work fine, I think you missed an ).

Check out Apple's documentation: Predicate Format String Syntax for more info.