Condition Structure Reference
public struct Condition : Equatable
A structure that defines conditional logic for determining whether data in your application
meets specific criteria. Conditions are the building blocks used by Rules to decide when
to trigger certain actions, such as dispatching events, collecting or transforming data.
## Overview
A Condition evaluates data from your application’s data layer against specified criteria.
For example, you might create a condition to check if a user’s subscription status equals “premium”,
or if a purchase amount is greater than $100.
## Basic Usage
For creating Condition instances it’s recommended to use the convenience
static methods provided in the Condition extension:
// Check if user type equals "premium"
let condition = Condition.equals(ignoreCase: false,
variable: "user_type", // for a flat key
target: "premium")
// Check if purchase amount is greater than 100
let condition = Condition.isGreaterThan(orEqual: false,
variable: JSONPath["order"]["purchase_amount"], // for a JSON path
number: "100")
## Error Handling
When conditions are evaluated, they may throw ConditionEvaluationError in exceptional cases:
- If the specified variable doesn’t exist in the data (except for
isDefined/isNotDefinedoperators) - If a required filter value is missing
- If numeric operations are attempted on non-numeric data
- If an operator is not supported for the data type found
## Supported Data Types
Conditions can evaluate various data types including strings, numbers, booleans, arrays, and dictionaries. The behavior varies by operator - for example, string operations will convert other types to strings, while numeric operations require parseable numbers.
-
The operator used to evaluate a condition against a variable.
See moreDeclaration
Swift
public enum Operator : Equatable -
Returns a
Conditionthat checks whether the value found at pathvariableis equal to the giventarget.Declaration
Swift
static func equals(ignoreCase: Bool, variable: JSONObjectPath, target: String) -> ConditionParameter Description ignoreCasetrueif the equality check should be done in a case-insensitive way; elsefalsevariablethe path to the variable in the payload to extract the value from for the comparison
targetthe target value to check against
-
Returns a
Conditionthat checks whether the value found at keyvariableis equal to the giventarget.Declaration
Swift
static func equals(ignoreCase: Bool, variable: String, target: String) -> ConditionParameter Description ignoreCasetrueif the equality check should be done in a case-insensitive way; elsefalsevariablethe key to the variable in the payload to extract the value from for the comparison
targetthe target value to check against
-
Returns a
Conditionthat checks whether the value found at pathvariableis not equal to the giventarget.Declaration
Swift
static func doesNotEqual(ignoreCase: Bool, variable: JSONObjectPath, target: String) -> ConditionParameter Description ignoreCasetrueif the equality check should be done in a case-insensitive way; elsefalsevariablethe path to the variable in the payload to extract the value from for the comparison
targetthe target value to check against
-
Returns a
Conditionthat checks whether the value found at keyvariableis not equal to the giventarget.Declaration
Swift
static func doesNotEqual(ignoreCase: Bool, variable: String, target: String) -> ConditionParameter Description ignoreCasetrueif the equality check should be done in a case-insensitive way; elsefalsevariablethe key to the variable in the payload to extract the value from for the comparison
targetthe target value to check against
-
Returns a
Conditionthat checks whether the value found at pathvariable, as a string, contains thestringwithin it.Declaration
Swift
static func contains(ignoreCase: Bool, variable: JSONObjectPath, string: String) -> ConditionParameter Description ignoreCasetrueif the comparison should be done in a case-insensitive way; elsefalsevariablethe path to the variable in the payload to extract the value from for the comparison
stringthe target value to check against
-
Returns a
Conditionthat checks whether the value found at keyvariable, as a string, contains thestringwithin it.Declaration
Swift
static func contains(ignoreCase: Bool, variable: String, string: String) -> ConditionParameter Description ignoreCasetrueif the comparison should be done in a case-insensitive way; elsefalsevariablethe key to the variable in the payload to extract the value from for the comparison
stringthe target value to check against
-
Returns a
Conditionthat checks whether the value found at pathvariable, as a string, does not contain thestringwithin it.Declaration
Swift
static func doesNotContain(ignoreCase: Bool, variable: JSONObjectPath, string: String) -> ConditionParameter Description ignoreCasetrueif the comparison should be done in a case-insensitive way; elsefalsevariablethe path to the variable in the payload to extract the value from for the comparison
stringthe target value to check against
-
Returns a
Conditionthat checks whether the value found at keyvariable, as a string, does not contain thestringwithin it.Declaration
Swift
static func doesNotContain(ignoreCase: Bool, variable: String, string: String) -> ConditionParameter Description ignoreCasetrueif the comparison should be done in a case-insensitive way; elsefalsevariablethe key to the variable in the payload to extract the value from for the comparison
stringthe target value to check against
-
Returns a
Conditionthat checks whether the value found at pathvariable, as a string, starts with the givenprefix.Declaration
Swift
static func startsWith(ignoreCase: Bool, variable: JSONObjectPath, prefix: String) -> ConditionParameter Description ignoreCasetrueif the comparison should be done in a case-insensitive way; elsefalsevariablethe path to the variable in the payload to extract the value from for the comparison
prefixthe target value to check against
-
Returns a
Conditionthat checks whether the value found at keyvariable, as a string, starts with the givenprefix.Declaration
Swift
static func startsWith(ignoreCase: Bool, variable: String, prefix: String) -> ConditionParameter Description ignoreCasetrueif the comparison should be done in a case-insensitive way; elsefalsevariablethe key to the variable in the payload to extract the value from for the comparison
prefixthe target value to check against
-
Returns a
Conditionthat checks whether the value found at pathvariable, as a string, does not start with the givenprefix.Declaration
Swift
static func doesNotStartWith(ignoreCase: Bool, variable: JSONObjectPath, prefix: String) -> ConditionParameter Description ignoreCasetrueif the comparison should be done in a case-insensitive way; elsefalsevariablethe path to the variable in the payload to extract the value from for the comparison
prefixthe target value to check against
-
Returns a
Conditionthat checks whether the value found at keyvariable, as a string, does not start with the givenprefix.Declaration
Swift
static func doesNotStartWith(ignoreCase: Bool, variable: String, prefix: String) -> ConditionParameter Description ignoreCasetrueif the comparison should be done in a case-insensitive way; elsefalsevariablethe key to the variable in the payload to extract the value from for the comparison
prefixthe target value to check against
-
Returns a
Conditionthat checks whether the value found at pathvariable, as a string, ends with the givensuffix.Declaration
Swift
static func endsWith(ignoreCase: Bool, variable: JSONObjectPath, suffix: String) -> ConditionParameter Description ignoreCasetrueif the comparison should be done in a case-insensitive way; elsefalsevariablethe path to the variable in the payload to extract the value from for the comparison
suffixthe target value to check against
-
Returns a
Conditionthat checks whether the value found at keyvariable, as a string, ends with the givensuffix.Declaration
Swift
static func endsWith(ignoreCase: Bool, variable: String, suffix: String) -> ConditionParameter Description ignoreCasetrueif the comparison should be done in a case-insensitive way; elsefalsevariablethe key to the variable in the payload to extract the value from for the comparison
suffixthe target value to check against
-
Returns a
Conditionthat checks whether the value found at pathvariable, as a string, does not end with the givensuffix.Declaration
Swift
static func doesNotEndWith(ignoreCase: Bool, variable: JSONObjectPath, suffix: String) -> ConditionParameter Description ignoreCasetrueif the comparison should be done in a case-insensitive way; elsefalsevariablethe path to the variable in the payload to extract the value from for the comparison
suffixthe target value to check against
-
Returns a
Conditionthat checks whether the value found at keyvariable, as a string, does not end with the givensuffix.Declaration
Swift
static func doesNotEndWith(ignoreCase: Bool, variable: String, suffix: String) -> ConditionParameter Description ignoreCasetrueif the comparison should be done in a case-insensitive way; elsefalsevariablethe key to the variable in the payload to extract the value from for the comparison
suffixthe target value to check against
-
Returns a
Conditionthat checks whether the value can be found at pathvariable.Declaration
Swift
static func isDefined(variable: JSONObjectPath) -> ConditionParameter Description variablethe path to the variable in the payload to extract the value from for the comparison
-
Returns a
Conditionthat checks whether the value can be found at keyvariable.Declaration
Swift
static func isDefined(variable: String) -> ConditionParameter Description variablethe key to the variable in the payload to extract the value from for the comparison
-
Returns a
Conditionthat checks whether the value can not be found at pathvariable.Declaration
Swift
static func isNotDefined(variable: JSONObjectPath) -> ConditionParameter Description variablethe path to the variable in the payload to extract the value from for the comparison
-
Returns a
Conditionthat checks whether the value can not be found at keyvariable.Declaration
Swift
static func isNotDefined(variable: String) -> ConditionParameter Description variablethe key to the variable in the payload to extract the value from for the comparison
-
Returns a
Conditionthat checks whether the value at pathvariableis considered to be “empty”.“Empty” is considered as the following for the different supported input types:
String.isEmptyArray.isEmptyDictionary.isEmptyvalue == NSNull()
Numeric values are always considered as not empty.
Declaration
Swift
static func isEmpty(variable: JSONObjectPath) -> ConditionParameter Description variablethe path to the variable in the payload to extract the value from for the comparison
-
Returns a
Conditionthat checks whether the value at keyvariableis considered to be “empty”.“Empty” is considered as the following for the different supported input types:
String.isEmptyArray.isEmptyDictionary.isEmptyvalue == NSNull()
Numeric values are always considered as not empty.
Declaration
Swift
static func isEmpty(variable: String) -> ConditionParameter Description variablethe key to the variable in the payload to extract the value from for the comparison
-
Returns a
Conditionthat checks whether the value at pathvariableis considered to be “not empty”.“Not empty” is considered as the following for the different supported input types:
!String.isEmpty!Array.isEmpty!Dictionary.isEmptyvalue != NSNull()
Numeric values are always considered as not empty.
Declaration
Swift
static func isNotEmpty(variable: JSONObjectPath) -> ConditionParameter Description variablethe path to the variable in the payload to extract the value from for the comparison
-
Returns a
Conditionthat checks whether the value at keyvariableis considered to be “not empty”.“Not empty” is considered as the following for the different supported input types:
!String.isEmpty!Array.isEmpty!Dictionary.isEmptyvalue != NSNull()
Numeric values are always considered as not empty.
Declaration
Swift
static func isNotEmpty(variable: String) -> ConditionParameter Description variablethe key to the variable in the payload to extract the value from for the comparison
-
Returns a
Conditionthat checks whether theDoublevalue found at pathvariable, is greater than theDoublevalue given bynumberDeclaration
Swift
static func isGreaterThan(orEqual: Bool, variable: JSONObjectPath, number: String) -> ConditionParameter Description orEqualtrueif numbers can also be equal; elsefalsevariablethe path to the variable in the payload to extract the value from for the comparison
numberthe target value to check against
-
Returns a
Conditionthat checks whether theDoublevalue found at keyvariable, is greater than theDoublevalue given bynumberDeclaration
Swift
static func isGreaterThan(orEqual: Bool, variable: String, number: String) -> ConditionParameter Description orEqualtrueif numbers can also be equal; elsefalsevariablethe key to the variable in the payload to extract the value from for the comparison
numberthe target value to check against
-
Returns a
Conditionthat checks whether theDoublevalue found at pathvariable, is less than theDoublevalue given bynumberDeclaration
Swift
static func isLessThan(orEqual: Bool, variable: JSONObjectPath, number: String) -> ConditionParameter Description orEqualtrueif numbers can also be equal; elsefalsevariablethe path to the variable in the payload to extract the value from for the comparison
numberthe target value to check against
-
Returns a
Conditionthat checks whether theDoublevalue found at keyvariable, is less than theDoublevalue given bynumberDeclaration
Swift
static func isLessThan(orEqual: Bool, variable: String, number: String) -> ConditionParameter Description orEqualtrueif numbers can also be equal; elsefalsevariablethe key to the variable in the payload to extract the value from for the comparison
numberthe target value to check against
-
Returns a
Conditionthat checks whether the value found at pathvariable, as a string, is matched by the givenregex.Declaration
Swift
static func regularExpression(variable: JSONObjectPath, regex: String) -> ConditionParameter Description variablethe path to the variable in the payload to extract the value from for the comparison
regexthe target regex to check against
-
Returns a
Conditionthat checks whether the value found at keyvariable, as a string, is matched by the givenregex.Declaration
Swift
static func regularExpression(variable: String, regex: String) -> ConditionParameter Description variablethe key to the variable in the payload to extract the value from for the comparison
regexthe target regex to check against