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 )-> JSONValueMatcherParameters
atLeastThe minimum acceptable value.
Return Value
A
JSONValueMatcherfor 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 ) -> JSONValueMatcherParameters
atLeastThe minimum acceptable value (inclusive).
atMostThe maximum acceptable value (inclusive).
Return Value
A
JSONValueMatcherfor 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 ) -> JSONValueMatcherParameters
atMostThe maximum acceptable value.
Return Value
A
JSONValueMatcherfor the specified condition. -
Creates a matcher for an exact number value.
Declaration
Swift
public class func matcherWhereNumberEquals( to number: Double ) -> JSONValueMatcherParameters
numberThe exact number to match.
Return Value
A
JSONValueMatcherfor the specified condition. -
Creates a matcher for an exact boolean value.
Declaration
Swift
public class func matcherWhereBooleanEquals( _ boolean: Bool ) -> JSONValueMatcherParameters
booleanThe exact boolean to match.
Return Value
A
JSONValueMatcherfor the specified condition. -
Creates a matcher for an exact string value.
Declaration
Swift
public class func matcherWhereStringEquals( _ string: String ) -> JSONValueMatcherParameters
stringThe exact string to match.
Return Value
A
JSONValueMatcherfor the specified condition. -
Creates a matcher that checks for the presence or absence of a value.
Declaration
Swift
public class func matcherWhereValueIsPresent( _ present: Bool ) -> JSONValueMatcherParameters
presentIf
true, the value must exist (not be null). Iffalse, it must not.Return Value
A
JSONValueMatcherfor 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
versionConstraintThe version constraint string (e.g., “1.0.0+”, “[1.0, 2.0)”).
Return Value
A
JSONValueMatcherfor 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
predicateThe predicate to apply to elements in the array.
Return Value
A
JSONValueMatcherfor 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
predicateThe predicate to apply to the element at the specified index.
indexThe index of the array element to check.
Return Value
A
JSONValueMatcherfor the specified condition. -
Declaration
Swift
public func encode(to encoder: any Encoder) throws -
Evaluates the given
AirshipJSONvalue against the matcher.Declaration
Swift
public func evaluate(json: AirshipJSON, ignoreCase: Bool = false) -> BoolParameters
jsonThe
AirshipJSONvalue to evaluate.ignoreCaseIf
true, string comparisons will be case-insensitive.Return Value
trueif the value matches, otherwisefalse.
View on GitHub