From dd301fbc0f9f988b47ad7b6532249833b3aa848c Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Mon, 26 Mar 2018 12:53:34 -0400 Subject: [ios, macos] Change the format for case expressions to a flat structure. (#11450) * [ios, macos] Change the format for case expressions to a flat structure. * [ios, macos] Add support for multiple branches case expression. * [ios, macos] Add multiple branch tests to case expressions. * [ios, macos] Case operator now has iOS 8 support. --- platform/darwin/src/NSPredicate+MGLAdditions.mm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'platform/darwin/src/NSPredicate+MGLAdditions.mm') diff --git a/platform/darwin/src/NSPredicate+MGLAdditions.mm b/platform/darwin/src/NSPredicate+MGLAdditions.mm index 63c8307803..2d5b646ff2 100644 --- a/platform/darwin/src/NSPredicate+MGLAdditions.mm +++ b/platform/darwin/src/NSPredicate+MGLAdditions.mm @@ -324,4 +324,29 @@ NSArray *MGLSubpredicatesWithJSONObjects(NSArray *objects) { return nil; } +- (id)mgl_case:(id)firstValue, ... { + + if ([self evaluateWithObject:nil]) { + return firstValue; + } + + id eachExpression; + va_list argumentList; + va_start(argumentList, firstValue); + + while ((eachExpression = va_arg(argumentList, id))) { + if ([eachExpression isKindOfClass:[NSComparisonPredicate class]]) { + id valueExpression = va_arg(argumentList, id); + if ([eachExpression evaluateWithObject:nil]) { + return valueExpression; + } + } else { + return eachExpression; + } + } + va_end(argumentList); + + return nil; +} + @end -- cgit v1.2.1