Jeff
Jeff

Reputation: 1403

How to use If inside NSPredicate?

Is it possible to use if inside NSPredicate? In my Student table there is one column sex (male/female). I want to use two queries for male and female.

NSPredicate *pred = [NSPredicate predicateWithFormat:@"if(sex=='male') query1  Else query2" ];

How do I implement this?

Upvotes: 0

Views: 52

Answers (1)

Alfonso
Alfonso

Reputation: 8482

You can use AND and OR to achieve this:

(sex = 'male' AND <query1>) OR (sex != 'male' AND <query2>)

Upvotes: 1

Related Questions