diff --git a/platform/darwin/docs/guides/Predicates and Expressions.md b/platform/darwin/docs/guides/Predicates and Expressions.md
index 6b191720b..b45434053 100644
--- a/platform/darwin/docs/guides/Predicates and Expressions.md
+++ b/platform/darwin/docs/guides/Predicates and Expressions.md
@@ -19,6 +19,8 @@ based on the feature’s attributes. Use the `MGLVectorStyleLayer.predicate`
property to include only the features in the source layer that satisfy a
condition that you define.
+### Operators
+
The following comparison operators are supported:
`NSPredicateOperatorType` | Format string syntax
@@ -31,8 +33,10 @@ The following comparison operators are supported:
`NSNotEqualToPredicateOperatorType` | `key != value`
`key <> value`
`NSBetweenPredicateOperatorType` | `key BETWEEN { 32, 212 }`
-The `key` may be cast explicitly into the key's type. Example: `CAST(key, 'NSNumber')` or
-`CAST(key, 'NSString')`
+To test whether a feature has or lacks a specific attribute, compare the
+attribute to `NULL` or `NIL`. Predicates created using the
+`+[NSPredicate predicateWithValue:]` method are also supported. String
+operators and custom operators are not supported.
The following compound operators are supported:
@@ -49,82 +53,53 @@ The following aggregate operators are supported:
`NSInPredicateOperatorType` | `key IN { 'iOS', 'macOS', 'tvOS', 'watchOS' }`
`NSContainsPredicateOperatorType` | `{ 'iOS', 'macOS', 'tvOS', 'watchOS' } CONTAINS key`
-To test whether a feature has or lacks a specific attribute, compare the
-attribute to `NULL` or `NIL`. Predicates created using the
-`+[NSPredicate predicateWithValue:]` method are also supported. String
-operators and custom operators are not supported.
+Operator modifiers such as `c` (for case insensitivity), `d` (for diacritic
+insensitivity), and `l` (for locale sensitivity) are unsupported for comparison
+and aggregate operators that are used in the predicate.
+
+### Operands
+
+Operands in predicates can be [variables](#variables), [key paths](#key-paths),
+or almost anything else that can appear
+[inside an expression](#using-expressions-to-configure-layout-and-paint-attributes).
+
+Automatic type casting is not performed. Therefore, a feature only matches a
+predicate if its value for the attribute in question is of the same type as the
+value specified in the predicate. Use the `CAST()` operator to convert a key
+path or variable into a matching type:
+
+* To cast a value to a number, use `CAST(key, 'NSNumber')`.
+* To cast a value to a string, use `CAST(key, 'NSString')`.
For details about the predicate format string syntax, consult the “Predicate
Format String Syntax” chapter of the
_[Predicate Programming Guide](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/AdditionalChapters/Introduction.html)_
in Apple developer documentation.
-Either the predicate’s left-hand or right-hand expression can be an `NSString`
-(to match strings) or `NSNumber` (to match numbers, including Boolean values)
-or an array of `NSString`s or `NSNumber`s, depending on the operator and the
-type of values expected for the attribute being tested or, alternatively,
-one of the following special attributes:
-
-
| Attribute | Meaning |
|---|---|
$featureIdentifier |
-
- A value that uniquely identifies the feature in the containing source.
- For details on the types of values that may be associated with this key,
- consult the documentation for the MGLFeature protocol’s
- identifier property.
- |
-
$geometryType |
-
- The type of geometry represented by the feature. A feature’s type is
- guaranteed to be one of the following strings:
-
|
-
point_count |
- The number of point features in a given cluster. | -
| Attribute | Type | Meaning |
|---|---|---|
point_count |
+ Number | +The number of point features in a given cluster. | +
| Selector name | Target | Arguments | Returns |
|---|---|---|---|
boolValue |
-
- An NSExpression that evaluates to a number or string.
- |
- - |
- A Boolean representation of the target: FALSE when then input is an
- empty string, 0, FALSE, NIL, or NaN, otherwise TRUE.
- |
-
mgl_has: |
-
- An NSExpression that evaluates to an NSDictionary or the evaluated object (SELF).
- |
-
- An NSExpression that evaluates to an NSString representing the key to look up in the dictionary or the feature attribute to look up in the evaluated object (see MGLFeature.attributes).
- |
-
- true if the dictionary has a value for the key or if the evaluated object has a value for the feature attribute.
- |
-
mgl_expressionWithContext: |
-
- An NSExpression that may contain references to the variables defined in
- the context dictionary.
- |
-
- An NSDictionary with NSStrings as keys and NSExpressions as values.
- Each key is a variable name and each value is the variable’s value within
- the target expression.
- |
- - The target expression with variable subexpressions replaced with the - values defined in the context dictionary. - | -
mgl_interpolateWithCurveType:parameters:stops: |
-
- An NSExpression that evaluates to a number and contains a variable or
- key path expression.
- |
-
- The first argument is one of the following strings denoting curve types:
- linear, exponential, or cubic-bezier.
-
- The second argument is an expression providing parameters for the curve:
-
-
NSDictionary object representing the
- interpolation’s stops, with numeric zoom levels as keys and expressions as
- values.
- |
- - A value interpolated along the continuous mathematical function defined by - the arguments, with the target as the input to the function. - | -
- mgl_numberWithFallbackValues:,
- doubleValue,
- floatValue,
- decimalValue
- |
-
- An NSExpression that evaluates to a Boolean value, number, or string.
- |
-
- Zero or more NSExpressions, each evaluating to a Boolean value or
- string.
- |
-
- A numeric representation of the target:
-
|
-
mgl_stepWithMinimum:stops: |
-
- An NSExpression that evaluates to a number and contains a variable or
- key path expression.
- |
-
- The first argument is an expression that evaluates to a number, specifying
- the minimum value in case the target is less than any of the stops in the
- second argument.
-
- The second argument is an NSDictionary object representing the
- interpolation’s stops, with numeric zoom levels as keys and expressions as
- values.
- |
- - The output value of the stop whose key is just less than the evaluated - target, or the minimum value if the target is less than the least of the - stops’ keys. - | -
stringByAppendingString: |
-
- An NSExpression that evaluates to a string.
- |
-
- One or more NSExpressions, each evaluating to a string.
- |
- - The target string with each of the argument strings appended in order. - | -
stringValue |
-
- An NSExpression that evaluates to a Boolean value, number, or string.
- |
- - |
- A string representation of the target:
-
|
-
$featureIdentifierNSExpression.featureIdentifierVariableExpression property.
+ $geometryTypePoint for point features, corresponding to the
+ MGLPointAnnotation class
+ LineString for polyline features, corresponding to
+ the MGLPolyline class
+ Polygon for polygon features, corresponding to the
+ MGLPolygon class
+ NSExpression.geometryTypeVariableExpression property.
+ $heatmapDensityheatmapColor property.
+ This variable corresponds to the
+ NSExpression.heatmapDensityVariableExpression property.
NSExpression.zoomLevelVariableExpression property.
mgl_does:have:mgl_does:have:(SELF, '🧀🍔') or mgl_does:have:(%@, '🧀🍔')mgl_interpolate:withCurveType:parameters:stops:mgl_interpolate:withCurveType:parameters:stops:(x, 'linear', nil, %@)mgl_step:from:stops:mgl_step:from:stops:(x, 11, %@)mgl_join:mgl_join({'Old', 'MacDonald'})mgl_acos:mgl_acos(1)mgl_asin:mgl_asin(0)mgl_atan:mgl_atan(20)mgl_cos:mgl_cos(0)mgl_log2:mgl_log2(1024)mgl_round:mgl_round(1.5)mgl_sin:mgl_sin(0)mgl_tan:mgl_tan(0)mgl_coalesce:mgl_coalesce({x, y, z})MGL_LET:MGL_LET('age', uppercase('old'), 'name', uppercase('MacDonald'), mgl_join({$age, $name}))NSExpression values, followed by an NSExpression
+ that may contain references to those variables.
+MGL_MATCH:MGL_MATCH(x, 0, 'zero match', 1, 'one match', 'two match', 'default')MGL_IF:MGL_IF(1 = 2, YES, 2 = 2, YES, NO)NSPredicate conditionals and resulting expressions,
+ followed by a default expression.
+MGL_FUNCTION:MGL_FUNCTION('typeof', mystery)boolValueFUNCTION(1, 'boolValue')NSExpression that evaluates to a number or string.
+FALSE when then input is an
+empty string, 0, FALSE, NIL, or NaN,
+otherwise TRUE.
+
+### `mgl_has:`
+
+mgl_has:FUNCTION($featureProperties, 'mgl_has:', '🧀🍔')NSExpression that evaluates to an NSDictionary
+ or the evaluated object (SELF).
+NSExpression that evaluates to an NSString
+ representing the key to look up in the dictionary or the feature attribute to
+ look up in the evaluated object (see MGLFeature.attributes).
+true if the dictionary has a value for the key or if the evaluated
+object has a value for the feature attribute.
+
+This function corresponds to the
+[`has`](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-has)
+operator in the Mapbox Style Specification. See also the
+[`mgl_does:have:`](#code-mgl_does-have-code) function, which is used on its own
+without the `FUNCTION()` operator. You can also check whether an object has an
+attribute by comparing the key path to `NIL`, for example `cheeseburger != NIL`
+or `burger.cheese != NIL`
+
+### `mgl_expressionWithContext:`
+
+mgl_expressionWithContext:FUNCTION($ios + $macos, 'mgl_expressionWithContext:', %@) with
+ a dictionary containing ios and macos keys
+NSExpression that may contain references to the variables
+ defined in the context dictionary.
+NSDictionary with NSStrings as keys and
+ NSExpressions as values. Each key is a variable name and each
+ value is the variable’s value within the target expression.
+mgl_interpolateWithCurveType:parameters:stops:FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', NIL, %@)
+ with a dictionary containing zoom levels or other constant values as keys
+NSExpression that evaluates to a number and contains a
+ variable or key path expression.
+linear, exponential, or cubic-bezier.
+
+ The second argument is an expression providing parameters for the curve:
+
+ linear, the argument is NIL.exponential, the argument is an
+ expression that evaluates to a number, specifying the base of the
+ exponential interpolation.
+ cubic-bezier, the argument is an
+ array or aggregate expression containing four expressions, each
+ evaluating to a number. The four numbers are control points for the
+ cubic Bézier curve.
+ NSDictionary object representing the
+ interpolation’s stops, with numeric zoom levels as keys and expressions as
+ values.
+mgl_numberWithFallbackValues:,
+ doubleValue,
+ floatValue, or
+ decimalValue
+FUNCTION(ele, 'mgl_numberWithFallbackValues:', 0)NSExpression that evaluates to a Boolean value, number, or
+ string.
+NSExpressions, each evaluating to a Boolean value
+ or string.
+NIL or FALSE, the result is 0.
+* If the target is true, the result is 1.
+ * If the target is a string, it is converted to a number as specified by the
+ “[ToNumber Applied to the String Type](https://tc39.github.io/ecma262/#sec-tonumber-applied-to-the-string-type)”
+ algorithm of the ECMAScript Language Specification.
+ * If multiple values are provided, each one is evaluated in order until the
+ first successful conversion is obtained.
+
+This function corresponds to the
+[`to-number`](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-to-number)
+operator in the Mapbox Style Specification. You can also cast a value to a
+number by passing the value and the string `NSNumber` into the `CAST()`
+operator.
+
+### `mgl_stepWithMinimum:stops:`
+
+mgl_stepWithMinimum:stops:FUNCTION($zoomLevel, 'mgl_stepWithMinimum:stops:', 0, %@) with
+ a dictionary with zoom levels or other constant values as keys
+NSExpression that evaluates to a number and contains a
+ variable or key path expression.
+NSDictionary object representing the
+ interpolation’s stops, with numeric zoom levels as keys and expressions as
+ values.
+stringByAppendingString:FUNCTION('Old', 'stringByAppendingString:', 'MacDonald')NSExpression that evaluates to a string.NSExpressions, each evaluating to a string.stringValueFUNCTION(ele, 'stringValue')NSExpression that evaluates to a Boolean value, number, or
+ string.
+NIL, the result is the empty string.
+* If the target is a Boolean value, the result is the string `true` or `false`.
+* If the target is a number, it is converted to a string as specified by the
+ “[NumberToString](https://tc39.github.io/ecma262/#sec-tostring-applied-to-the-number-type)”
+ algorithm of the ECMAScript Language Specification.
+* If the target is a color, it is converted to a string of the form
+ `rgba(r,g,b,a)`, where r, g, and b are
+ numerals ranging from 0 to 255 and a ranges from 0 to 1.
+* Otherwise, the target is converted to a string in the format specified by the
+ [`JSON.stringify()`](https://tc39.github.io/ecma262/#sec-json.stringify)
+ function of the ECMAScript Language Specification.
+
+This function corresponds to the
+[`to-string`](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-to-string)
+operator in the Mapbox Style Specification. You can also cast a value to a
+string by passing the value and the string `NSString` into the `CAST()`
+operator.
diff --git a/platform/darwin/docs/theme/assets/css/jazzy.css.scss b/platform/darwin/docs/theme/assets/css/jazzy.css.scss
index ad0a3b708..ff6d2a374 100644
--- a/platform/darwin/docs/theme/assets/css/jazzy.css.scss
+++ b/platform/darwin/docs/theme/assets/css/jazzy.css.scss
@@ -113,7 +113,12 @@ h2 {
}
h3 {
- @include heading(14px, 1em 0 0.3em);
+ @include heading(1.2rem, 1em 0 0.3em);
+}
+
+h3 > code {
+ font-weight: bold;
+ font-size: 1.2rem;
}
h4 {
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.h b/platform/darwin/src/NSExpression+MGLAdditions.h
index 39a841543..64cbe9741 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.h
+++ b/platform/darwin/src/NSExpression+MGLAdditions.h
@@ -16,7 +16,7 @@ typedef NSString *MGLExpressionInterpolationMode NS_TYPED_ENUM;
This attribute corresponds to the `linear` value in the
interpolate
- expression reference in the Mapbox Style Specification.
+ expression operator in the Mapbox Style Specification.
*/
extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolationModeLinear;
@@ -25,7 +25,7 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio
This attribute corresponds to the `exponential` value in the
interpolate
- expression reference in the Mapbox Style Specification.
+ expression operator in the Mapbox Style Specification.
*/
extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolationModeExponential;
@@ -34,50 +34,55 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio
This attribute corresponds to the `cubic-bezier` value in the
interpolate
- expression reference in the Mapbox Style Specification.
+ expression operator in the Mapbox Style Specification.
*/
extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier;
-@interface NSExpression (MGLVariableAdditions)
+/**
+ Methods for creating expressions that use Mapbox-specific functionality and for
+ converting to and from the JSON format defined in the
+ Mapbox Style Specification.
+ */
+@interface NSExpression (MGLAdditions)
+
+#pragma mark Creating Variable Expressions
/**
`NSExpression` variable that corresponds to the
zoom
- expression reference in the Mapbox Style Specification.
+ expression operator in the Mapbox Style Specification.
*/
@property (class, nonatomic, readonly) NSExpression *zoomLevelVariableExpression;
/**
`NSExpression` variable that corresponds to the
heatmap-density
- expression reference in the Mapbox Style Specification.
+ expression operator in the Mapbox Style Specification.
*/
@property (class, nonatomic, readonly) NSExpression *heatmapDensityVariableExpression;
/**
`NSExpression` variable that corresponds to the
geometry-type
- expression reference in the Mapbox Style Specification.
+ expression operator in the Mapbox Style Specification.
*/
@property (class, nonatomic, readonly) NSExpression *geometryTypeVariableExpression;
/**
`NSExpression` variable that corresponds to the
id
- expression reference in the Mapbox Style Specification.
+ expression operator in the Mapbox Style Specification.
*/
@property (class, nonatomic, readonly) NSExpression *featureIdentifierVariableExpression;
/**
`NSExpression` variable that corresponds to the
properties
- expression reference in the Mapbox Style Specification.
+ expression operator in the Mapbox Style Specification.
*/
@property (class, nonatomic, readonly) NSExpression *featurePropertiesVariableExpression;
-@end
-
-@interface NSExpression (MGLInitializerAdditions)
+#pragma mark Creating Conditional Expressions
/**
Returns a conditional function expression specifying the string predicate, and
@@ -89,6 +94,8 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio
*/
+ (instancetype)mgl_expressionForConditional:(nonnull NSPredicate *)conditionPredicate trueExpression:(nonnull NSExpression *)trueExpression falseExpresssion:(nonnull NSExpression *)falseExpression NS_SWIFT_NAME(init(forMGLConditional:trueExpression:falseExpression:));
+#pragma mark Creating Ramp, Scale, and Curve Expressions
+
/**
Returns a step function expression specifying the stepping, from expression
and stops.
@@ -121,6 +128,9 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio
@param defaultExpression The defaultValue expression to be used in case there is no match.
*/
+ (instancetype)mgl_expressionForMatchingExpression:(nonnull NSExpression *)inputExpression inDictionary:(nonnull NSDictionary