ConditionalExpression
public class ConditionalExpression : FunctionExpression, @unchecked SendableA ConditionalExpression is a FunctionExpression that evaluates to one of two expressions
based on a boolean condition.
This is equivalent to a ternary operator (condition ? then : else).
Example of using ConditionalExpression:
// Create a new field "status" based on the "rating" field.
// If rating > 4.5, status is "top_rated", otherwise "regular".
firestore.pipeline()
.collection("products")
.addFields([
ConditionalExpression(
Field("rating").greaterThan(4.5),
then: Constant("top_rated"),
else: Constant("regular")
).as("status")
])
-
Creates a new
ConditionalExpression.Declaration
Swift
public init(_ expression: BooleanExpression, then thenExpression: Expression, else elseExpression: Expression)Parameters
expressionThe
BooleanExpressionto evaluate.thenExpressionThe
Expressionto evaluate if the boolean expression istrue.elseExpressionThe
Expressionto evaluate if the boolean expression isfalse.