Repository navigation
[ios, macos] Add lookup and feature operators. - #11528
Conversation
3167c94 to
9b08744
Compare
|
By the way, I’ve been using this header as a guide to which built-in syntaxes (like subscripting) correspond to which built-in expression functions ( |
There was a problem hiding this comment.
[NSExpression expressionWithFormat:@"{1, 2, 3}[index]"] has a function of objectFrom:withIndex: and an arguments consisting of the expression index.
There was a problem hiding this comment.
Conventional custom functions should be prefixed with mgl_ to avoid conflicting with functions that Apple may add to NSExpression in the future.
There was a problem hiding this comment.
This SDK is using the $variable syntax both for these special built-in values that vary based on the execution context and also for user-defined variables. The assumption with zoomLevel and the like is that developers will be less likely to need a variable by that exact name.
There was a problem hiding this comment.
For consistency with Cocoa and this SDK, either spell this function featureID or, better yet, featureIdentifier.
There was a problem hiding this comment.
The has operator has two forms. You can think of the ["has", "something"] form as shorthand for ["has", "something", ["properties"]]. This PR only implements one of the two forms.
["has", "something"] should translate to FUNCTION(self, 'mgl_has:', 'something'), and ["has", "something", object] should translate to FUNCTION(object, 'mgl_has:', 'something').
441a524 to
ae3df5c
Compare
| NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(argumentObjects); | ||
| NSExpression *operand = argumentObjects.count > 1 ? subexpressions[1] : [NSExpression expressionWithFormat:@"self"]; | ||
| NSExpression *property = subexpressions.firstObject; | ||
| return [NSExpression expressionWithFormat:@"FUNCTION(%@, 'mgl_has:', %@)", operand, property]; |
There was a problem hiding this comment.
By the way, a preexisting way to write this in an expression would be FUNCTION(%@, 'valueForKey:', %@) != nil. That seems a bit more natural, although I guess mgl_has: will be slightly more ergonomic once we implement an aftermarket function for it.
There was a problem hiding this comment.
For this case mgl_has: seems like the most ergonomic option as its closer to our spec.
| if ([self.variable isEqualToString:@"mgl_geometryType"]) { | ||
| return @[@"geometry-type"]; | ||
| } | ||
| if ([self.variable isEqualToString:@"featureIdentifier"]) { |
There was a problem hiding this comment.
mgl_geometryType is prefixed with the class prefix, but featureIdentifier and featureProperties are not.
| return self.arguments.firstObject.mgl_jsonExpressionObject; | ||
| } else if ([function isEqualToString:@"mgl_has:"]) { | ||
| NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"has", self.arguments[0].mgl_jsonExpressionObject, nil]; | ||
| if (self.operand.expressionType == NSConstantValueExpressionType) { |
There was a problem hiding this comment.
FUNCTION($featureProperties, 'mgl_has:', 'property') should be translated as ["has", ["properties"], "property"], so we need to check here that the operand isn’t an NSEvaluatedObjectExpressionType (i.e., SELF).
Fixes #11006
Add operators