JSONValueMatcher
public final class JSONValueMatcher : NSObject, Sendable, Codable
A JSONValueMatcher
is used to match a JSON value against a set of constraints.
This class provides a flexible way to define conditions for JSON values, such as checking for equality,
numerical ranges, presence of a value, version constraints, and conditions on array elements.
It is Codable
, allowing it to be easily serialized and deserialized.
-
A protocol for defining the specific logic of a JSON value matcher. Each predicate implementation checks a JSON value against a specific condition.
See moreDeclaration
Swift
public protocol Predicate : Decodable, Encodable, Hashable, Sendable
-
Declaration
Swift
public init(from decoder: any Decoder) throws
-
Creates a matcher that requires a number to be at least a minimum value.
Declaration
Swift
public class func matcherWhereNumberAtLeast( _ atLeast: Double )-> JSONValueMatcher
Parameters
atLeast
The minimum acceptable value.
Return Value
A
JSONValueMatcher
for the specified condition. -
Creates a matcher that requires a number to be within a specified range.
Declaration
Swift
public class func matcherWhereNumberAtLeast( _ atLeast: Double, atMost: Double ) -> JSONValueMatcher
Parameters
atLeast
The minimum acceptable value (inclusive).
atMost
The maximum acceptable value (inclusive).
Return Value
A
JSONValueMatcher
for the specified condition. -
Creates a matcher that requires a number to be at most a maximum value.
Declaration
Swift
public class func matcherWhereNumberAtMost( _ atMost: Double ) -> JSONValueMatcher
Parameters
atMost
The maximum acceptable value.
Return Value
A
JSONValueMatcher
for the specified condition. -
Creates a matcher for an exact number value.
Declaration
Swift
public class func matcherWhereNumberEquals( to number: Double ) -> JSONValueMatcher
Parameters
number
The exact number to match.
Return Value
A
JSONValueMatcher
for the specified condition. -
Creates a matcher for an exact boolean value.
Declaration
Swift
public class func matcherWhereBooleanEquals( _ boolean: Bool ) -> JSONValueMatcher
Parameters
boolean
The exact boolean to match.
Return Value
A
JSONValueMatcher
for the specified condition. -
Creates a matcher for an exact string value.
Declaration
Swift
public class func matcherWhereStringEquals( _ string: String ) -> JSONValueMatcher
Parameters
string
The exact string to match.
Return Value
A
JSONValueMatcher
for the specified condition. -
Creates a matcher that checks for the presence or absence of a value.
Declaration
Swift
public class func matcherWhereValueIsPresent( _ present: Bool ) -> JSONValueMatcher
Parameters
present
If
true
, the value must exist (not be null). Iffalse
, it must not.Return Value
A
JSONValueMatcher
for the specified condition. -
Creates a matcher that checks a value against a version constraint. The value being checked is expected to be a string representing a version.
Declaration
Swift
public class func matcherWithVersionConstraint( _ versionConstraint: String ) -> JSONValueMatcher?
Parameters
versionConstraint
The version constraint string (e.g., “1.0.0+”, “[1.0, 2.0)”).
Return Value
A
JSONValueMatcher
for the specified condition. -
Creates a matcher that checks if an array contains an element that matches a
JSONPredicate
.Declaration
Swift
public class func matcherWithArrayContainsPredicate( _ predicate: JSONPredicate ) -> JSONValueMatcher?
Parameters
predicate
The predicate to apply to elements in the array.
Return Value
A
JSONValueMatcher
for the specified condition. -
Creates a matcher that checks if an array element at a specific index matches a
JSONPredicate
.Declaration
Swift
public class func matcherWithArrayContainsPredicate( _ predicate: JSONPredicate, at index: Int ) -> JSONValueMatcher?
Parameters
predicate
The predicate to apply to the element at the specified index.
index
The index of the array element to check.
Return Value
A
JSONValueMatcher
for the specified condition. -
Declaration
Swift
public func encode(to encoder: any Encoder) throws
-
Evaluates the given
AirshipJSON
value against the matcher.Declaration
Swift
public func evaluate(json: AirshipJSON, ignoreCase: Bool = false) -> Bool
Parameters
json
The
AirshipJSON
value to evaluate.ignoreCase
If
true
, string comparisons will be case-insensitive.Return Value
true
if the value matches, otherwisefalse
.