MJExtensionValidation provides an opportunity of validating converted model objects for MJExtension (A fast, convenient and nonintrusive conversion framework between JSON and model).
为 MJExtension 的 JSON-to-Model 转换增加校验接口。
pod 'MJExtensionValidation'
Implement +mj_validateConvertedObject:withKeyValues:
method for your model to validate the converted object:
#import <MJExtensionValidation/MJExtensionValidation.h>
@implementation User
+ (BOOL)mj_validateConvertedObject:(User *)user withKeyValues:(id)keyValues
{
return user.ID.length > 0;
}
@end
Then the JSON-to-model converting methods such as +mj_objectWithKeyValues:
will return nil
if the converted object could not pass the validation.
MJExtensionValidation is available under the MIT license. See the LICENSE file for more info.