UAJSONValueMatcher

@interface UAJSONValueMatcher : NSObject

Defines a JSON value matcher.

  • The matcher’s JSON payload.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSDictionary *_Nonnull payload;

    Swift

    var payload: [AnyHashable : Any] { get }
  • Factory method to create a matcher for a number that is at least the specified number.

    Declaration

    Objective-C

    + (nonnull instancetype)matcherWhereNumberAtLeast:(nonnull NSNumber *)number;

    Swift

    convenience init(whereNumberAtLeast number: NSNumber)

    Parameters

    number

    The lower bound for the number.

    Return Value

    A value matcher.

  • Factory method to create a matcher for a number between the lowerNumber and higherNumber.

    Declaration

    Objective-C

    + (nonnull instancetype)
        matcherWhereNumberAtLeast:(nonnull NSNumber *)lowerNumber
                           atMost:(nonnull NSNumber *)higherNumber;

    Swift

    convenience init(whereNumberAtLeast lowerNumber: NSNumber, atMost higherNumber: NSNumber)

    Parameters

    lowerNumber

    The lower bound for the number.

    higherNumber

    The upper bound for the number.

    Return Value

    A value matcher.

  • Factory method to create a matcher for a number that is at most the specified number.

    Declaration

    Objective-C

    + (nonnull instancetype)matcherWhereNumberAtMost:(nonnull NSNumber *)number;

    Swift

    convenience init(whereNumberAtMost number: NSNumber)

    Parameters

    number

    The upper bound for the number.

    Return Value

    A value matcher.

  • Factory method to create a matcher for an exact number.

    Declaration

    Objective-C

    + (nonnull instancetype)matcherWhereNumberEquals:(nonnull NSNumber *)number;

    Swift

    convenience init(whereNumberEquals number: NSNumber)

    Parameters

    number

    The expected number value.

    Return Value

    A value matcher.

  • Factory method to create a matcher for an exact boolean.

    Declaration

    Objective-C

    + (nonnull instancetype)matcherWhereBooleanEquals:(BOOL)boolean;

    Swift

    convenience init(whereBooleanEquals boolean: Bool)

    Parameters

    boolean

    The expected boolean value.

    Return Value

    A value matcher.

  • Factory method to create a matcher for an exact string.

    Declaration

    Objective-C

    + (nonnull instancetype)matcherWhereStringEquals:(nonnull NSString *)string;

    Swift

    convenience init(whereStringEquals string: String)

    Parameters

    string

    The expected string value.

    Return Value

    A value matcher.

  • Factory method to create a matcher for the presence of a value.

    Declaration

    Objective-C

    + (nonnull instancetype)matcherWhereValueIsPresent:(BOOL)present;

    Swift

    convenience init(whereValueIsPresent present: Bool)

    Parameters

    present

    YES if the value must be present, otherwise NO.

    Return Value

    A value matcher.

  • Factory method to create a matcher for a version constraint.

    Declaration

    Objective-C

    + (nullable instancetype)matcherWithVersionConstraint:
        (nonnull NSString *)versionConstraint;

    Swift

    convenience init?(versionConstraint: String)

    Parameters

    versionConstraint

    The version constraint to be matched against.

    Return Value

    A value matcher.

  • Factory method to create a matcher for an array value.

    Declaration

    Objective-C

    + (nullable instancetype)matcherWithArrayContainsPredicate:
        (nonnull UAJSONPredicate *)predicate;

    Swift

    convenience init?(arrayContains predicate: UAJSONPredicate)

    Parameters

    predicate

    A predicate to be used to evaluate each value in the array for a match.

    Return Value

    A value matcher.

  • Factory method to create a matcher for a value in an array.

    Declaration

    Objective-C

    + (nullable instancetype)matcherWithArrayContainsPredicate:
                                 (nonnull UAJSONPredicate *)predicate
                                                       atIndex:(NSUInteger)index;

    Swift

    convenience init?(arrayContains predicate: UAJSONPredicate, at index: UInt)

    Parameters

    predicate

    A predicate to be used to evaluate the value at the index.

    index

    The array index.

    Return Value

    A value matcher.

  • Factory method to create a matcher from a JSON payload.

    Declaration

    Objective-C

    + (nullable instancetype)matcherWithJSON:(nonnull id)json
                                       error:(NSError *_Nullable *_Nullable)error;

    Swift

    convenience init(json: Any) throws

    Parameters

    json

    The JSON payload.

    error

    An NSError pointer for storing errors, if applicable.

    Return Value

    A value matcher, or nil if the JSON is invalid.

  • Evaluates the object with the matcher.

    Declaration

    Objective-C

    - (BOOL)evaluateObject:(nullable id)object;

    Swift

    func evaluateObject(_ object: Any?) -> Bool

    Parameters

    object

    The object to evaluate.

    Return Value

    YES if the matcher matches the object, otherwise NO.

  • Evaluates the object with the matcher.

    Declaration

    Objective-C

    - (BOOL)evaluateObject:(nullable id)object ignoreCase:(BOOL)ignoreCase;

    Swift

    func evaluateObject(_ object: Any?, ignoreCase: Bool) -> Bool

    Parameters

    object

    The object to evaluate.

    ignoreCase

    {@code YES} to ignore case when checking String values, {@code NO} to check case. Strings contained in arrays and dictionaries also follow this rule.

    Return Value

    YES if the matcher matches the object, otherwise NO.