Reputation: 730
I need to fetch data from Core data, for that , I need to check Condition1 and Condition 2 using NSPredicate. But I only need to check the condition 2 once condition 1 satisfied . Any one please help me to achieve this scenario ?
Logic
If (Condition1 == true)
{
if(Condition2 == True)
{
}
else
{
//Code
}
}
else
{
//codes
}
Please help me to achieve this scenario using NSPredicate.
Upvotes: 0
Views: 169
Reputation: 90531
Just use an AND
expression in your predicate format string. NSPredicate
treats those as short-circuiting operators. That's implicit in this advice from the Predicate Programming Guide: Using Predicates – Performance Considerations section:
You should structure compound predicates to minimize the amount of work done. Regular expression matching in particular is an expensive operation. In a compound predicate, you should therefore perform simple tests before a regular expression […]:
In the […] example, the regular expression [after an
OR
] is evaluated only if the first clause is false.
(Emphasis added)
Upvotes: 1