summaryrefslogtreecommitdiff
path: root/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm')
-rw-r--r--platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm30
1 files changed, 29 insertions, 1 deletions
diff --git a/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm b/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm
index 0039b5af82..19568b8033 100644
--- a/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm
+++ b/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm
@@ -1,7 +1,7 @@
#import "NSCompoundPredicate+MGLAdditions.h"
#import "NSPredicate+MGLAdditions.h"
-#import "NSExpression+MGLAdditions.h"
+#import "NSExpression+MGLPrivateAdditions.h"
@implementation NSCompoundPredicate (MGLAdditions)
@@ -71,3 +71,31 @@
}
@end
+
+@implementation NSCompoundPredicate (MGLExpressionAdditions)
+
+- (id)mgl_jsonExpressionObject {
+ switch (self.compoundPredicateType) {
+ case NSNotPredicateType: {
+ NSAssert(self.subpredicates.count <= 1, @"NOT predicate cannot have multiple subpredicates.");
+ NSPredicate *subpredicate = self.subpredicates.firstObject;
+ return @[@"!", subpredicate.mgl_jsonExpressionObject];
+ }
+
+ case NSAndPredicateType: {
+ NSArray *subarrays = [self.subpredicates valueForKeyPath:@"mgl_jsonExpressionObject"];
+ return [@[@"all"] arrayByAddingObjectsFromArray:subarrays];
+ }
+
+ case NSOrPredicateType: {
+ NSArray *subarrays = [self.subpredicates valueForKeyPath:@"mgl_jsonExpressionObject"];
+ return [@[@"any"] arrayByAddingObjectsFromArray:subarrays];
+ }
+ }
+
+ [NSException raise:@"Compound predicate type not handled"
+ format:@""];
+ return nil;
+}
+
+@end