forked from mrcarlberg/LightObject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPPredicate+ConvenienceMethods.j
48 lines (39 loc) · 2.45 KB
/
CPPredicate+ConvenienceMethods.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* CPPredicate+ConvenienceMethods.j
*
* Created by Martin Carlberg on Januaray 28, 2016.
* Copyright 2016, All rights reserved.
*/
@import <Foundation/CPPredicate.j>
@implementation CPPredicate (PredicateConvenienceMethods)
+ (CPPredicate)keyPath:(CPString)aKeyPath equalsConstantValue:(CPObject)aValue {
return [CPPredicate keyPath:aKeyPath comparedToConstantValue:aValue operatorType:CPEqualToPredicateOperatorType];
}
+ (CPPredicate)keyPath:(CPString)aKeyPath notEqualsConstantValue:(CPObject)aValue {
return [CPPredicate keyPath:aKeyPath comparedToConstantValue:aValue operatorType:CPNotEqualToPredicateOperatorType];
}
+ (CPPredicate)constantValue:(CPString)inValue inKeyPath:(CPString)aKeyPath {
return [CPComparisonPredicate predicateWithLeftExpression:[CPExpression expressionForConstantValue:inValue]
rightExpression:[CPExpression expressionForKeyPath:aKeyPath]
modifier:CPDirectPredicateModifier
type:CPInPredicateOperatorType
options:0];
}
+ (CPPredicate)keyPath:(CPString)aKeyPath inConstantValues:(CPArray)inValues {
return [CPComparisonPredicate predicateWithLeftExpression:[CPExpression expressionForKeyPath:aKeyPath]
rightExpression:[CPExpression expressionForConstantValue:inValues]
modifier:CPDirectPredicateModifier
type:CPInPredicateOperatorType
options:0];
}
+ (CPPredicate)keyPath:(CPString)aKeyPath notInConstantValues:(CPArray)inValues {
return [CPCompoundPredicate notPredicateWithSubpredicate:[self keyPath:aKeyPath inConstantValues:inValues]];
}
+ (CPPredicate)keyPath:(CPString)aKeyPath comparedToConstantValue:(CPObject)aValue operatorType:(CPPredicateOperatorType)aType {
return [CPComparisonPredicate predicateWithLeftExpression:[CPExpression expressionForKeyPath:aKeyPath]
rightExpression:[CPExpression expressionForConstantValue:aValue]
modifier:CPDirectPredicateModifier
type:aType
options:0];
}
@end