MBAttributeValidator Class Reference
Inherits from | NSObject |
---|---|
Declared in | MBAttributeValidator.h |
Overview
MBAttributeValidator
instances can be used to verify that a given
MBDataModel
contains an expected set of values.
+ validatorForDataModel:
Returns a new MBAttributeValidator
to be used for validating the specified
MBDataModel
.
+ (nonnull instancetype)validatorForDataModel:(nonnull MBDataModel *)model
Parameters
model |
The |
---|
Declared In
MBAttributeValidator.h
model
Returns the MBDataModel
that the receiver was constructed to validate.
@property (nonnull, nonatomic, readonly) MBDataModel *model
Declared In
MBAttributeValidator.h
validationErrorMessages
Returns an array of NSString
s containing error messages for any problems
encountered during validation. Will be nil
if no validation errors
have occurred.
@property (nullable, nonatomic, readonly) NSArray *validationErrorMessages
Declared In
MBAttributeValidator.h
– require:or:
Requires that the data model contain either attr1
or attr2
but not
both.
- (BOOL)require:(nonnull NSString *)attr1 or:(nonnull NSString *)attr2
Parameters
attr1 |
The name of the first attribute. |
---|---|
attr2 |
The name of the second attribute. |
Return Value
YES
if the validation requirement was satisfied; NO
otherwise.
Declared In
MBAttributeValidator.h
– require:or:butNotBoth:
Requires that the data model contain either attr1
or attr2
.
- (BOOL)require:(nonnull NSString *)attr1 or:(nonnull NSString *)attr2 butNotBoth:(BOOL)onlyAllowOne
Parameters
attr1 |
The name of the first attribute. |
---|---|
attr2 |
The name of the second attribute. |
onlyAllowOne |
If |
Return Value
YES
if the validation requirement was satisfied; NO
otherwise.
Declared In
MBAttributeValidator.h
– requireAtLeastOneOf:
Requires at least one of a set of attribute names to be present in the data model. Validation will fail if none of the specified attributes are present.
- (BOOL)requireAtLeastOneOf:(nonnull NSObject<NSFastEnumeration> *)attrs
Parameters
attrs |
An enumeration of |
---|
Return Value
YES
if the validation requirement was satisfied; NO
otherwise.
Declared In
MBAttributeValidator.h
– requireExactlyOneOf:
Requires exactly one of a set of attribute names to be present in the data model. Validation will fail if none of the specified attributes are present, or if more than one is present.
- (BOOL)requireExactlyOneOf:(nonnull NSObject<NSFastEnumeration> *)attrs
Parameters
attrs |
An enumeration of |
---|
Return Value
YES
if the validation requirement was satisfied; NO
otherwise.
Declared In
MBAttributeValidator.h
– validate
Returns YES
if all validation requirements were satisfied.
- (BOOL)validate
Return Value
YES
if validation succeeded; NO
otherwise.
Discussion
If validation did not succeed, the error messages contained in
validationErrorMessages
will be logged to the console.
Declared In
MBAttributeValidator.h