Skip to content

Commit

Permalink
pretty code
Browse files Browse the repository at this point in the history
  • Loading branch information
ibireme committed Mar 15, 2016
1 parent e653d4c commit fb43fab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
25 changes: 13 additions & 12 deletions YYModel/NSObject+YYModel.h
Expand Up @@ -382,32 +382,33 @@ NS_ASSUME_NONNULL_BEGIN
+ (nullable NSArray<NSString *> *)modelPropertyWhitelist;

/**
If the default json-to-model transform does not fit to your model object, implement
this method to do additional process. You can also use this method to validate the
model's properties.
This method's behavior is similar to `- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic;`,
but be called before the model transform.
@discussion If the model implements this method, it will be called at the end of
@discussion If the model implements this method, it will be called before
`+modelWithJSON:`, `+modelWithDictionary:`, `-modelSetWithJSON:` and `-modelSetWithDictionary:`.
If this method returns NO, the transform process will ignore this model.
If this method returns nil, the transform process will ignore this model.
@param dic The json/kv dictionary.
@return Returns YES if the model is valid, or NO to ignore this model.
@return Returns the modified dictionary, or nil to ignore this model.
*/
- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic;
- (NSDictionary *)modelCustomWillTransformFromDictionary:(NSDictionary *)dic;

/**
This method's behavior is similar to `- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic;`, but be called before the model transform.
If the default json-to-model transform does not fit to your model object, implement
this method to do additional process. You can also use this method to validate the
model's properties.
@discussion If the model implements this method, it will be called before
@discussion If the model implements this method, it will be called at the end of
`+modelWithJSON:`, `+modelWithDictionary:`, `-modelSetWithJSON:` and `-modelSetWithDictionary:`.
If this method returns nil, the transform process will ignore this model.
If this method returns NO, the transform process will ignore this model.
@param dic The json/kv dictionary.
@return Returns NSDictionary for change the json/kv dictionary, or nil to ignore this model.
@return Returns YES if the model is valid, or NO to ignore this model.
*/
- (NSDictionary *)modelCustomWillTransformFromDictionary:(NSDictionary *)dic;
- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic;

/**
If the default model-to-json transform does not fit to your model class, implement
Expand Down
7 changes: 3 additions & 4 deletions YYModel/NSObject+YYModel.m
Expand Up @@ -418,9 +418,8 @@ @interface _YYModelMeta : NSObject {
/// Model class type.
YYEncodingNSType _nsType;

BOOL _hasCustomTransformFromDictionary;
BOOL _hasCustomWillTransformFromDictionary;

BOOL _hasCustomTransformFromDictionary;
BOOL _hasCustomTransformToDictionary;
BOOL _hasCustomClassFromDictionary;
}
Expand Down Expand Up @@ -560,11 +559,11 @@ - (instancetype)initWithClass:(Class)cls {
_classInfo = classInfo;
_keyMappedCount = _allPropertyMetas.count;
_nsType = YYClassGetNSType(cls);
_hasCustomWillTransformFromDictionary = ([cls instancesRespondToSelector:@selector(modelCustomWillTransformFromDictionary:)]);
_hasCustomTransformFromDictionary = ([cls instancesRespondToSelector:@selector(modelCustomTransformFromDictionary:)]);
_hasCustomTransformToDictionary = ([cls instancesRespondToSelector:@selector(modelCustomTransformToDictionary:)]);
_hasCustomClassFromDictionary = ([cls respondsToSelector:@selector(modelCustomClassForDictionary:)]);
_hasCustomWillTransformFromDictionary = ([cls instancesRespondToSelector:@selector(modelCustomWillTransformFromDictionary:)]);


return self;
}

Expand Down

0 comments on commit fb43fab

Please sign in to comment.