ibireme %!s(int64=9) %!d(string=hai) anos
pai
achega
fb43fabf0a
Modificáronse 2 ficheiros con 16 adicións e 16 borrados
  1. 13 12
      YYModel/NSObject+YYModel.h
  2. 3 4
      YYModel/NSObject+YYModel.m

+ 13 - 12
YYModel/NSObject+YYModel.h

@@ -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

+ 3 - 4
YYModel/NSObject+YYModel.m

@@ -418,9 +418,8 @@ static force_inline id YYValueForMultiKeys(__unsafe_unretained NSDictionary *dic
     /// Model class type.
     YYEncodingNSType _nsType;
     
-    BOOL _hasCustomTransformFromDictionary;
     BOOL _hasCustomWillTransformFromDictionary;
-
+    BOOL _hasCustomTransformFromDictionary;
     BOOL _hasCustomTransformToDictionary;
     BOOL _hasCustomClassFromDictionary;
 }
@@ -560,11 +559,11 @@ static force_inline id YYValueForMultiKeys(__unsafe_unretained NSDictionary *dic
     _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;
 }