Răsfoiți Sursa

adjust code

ibireme 9 ani în urmă
părinte
comite
c093c35e12
2 a modificat fișierele cu 5 adăugiri și 15 ștergeri
  1. 4 14
      YYModel/NSObject+YYModel.m
  2. 1 1
      YYModelTests/YYTestModelToJSON.m

+ 4 - 14
YYModel/NSObject+YYModel.m

@@ -484,7 +484,7 @@ static force_inline id YYValueForMultiKeys(__unsafe_unretained NSDictionary *dic
                                                                     propertyInfo:propertyInfo
                                                                          generic:genericMapper[propertyInfo.name]];
             if (!meta || !meta->_name) continue;
-            if (!meta->_getter && !meta->_setter) continue;
+            if (!meta->_getter || !meta->_setter) continue;
             if (allPropertyMetas[meta->_name]) continue;
             allPropertyMetas[meta->_name] = meta;
         }
@@ -1167,18 +1167,8 @@ static id ModelToJSONObjectRecursive(NSObject *model) {
         } else {
             switch (propertyMeta->_type & YYEncodingTypeMask) {
                 case YYEncodingTypeObject: {
-                    /*
-                     When send the getter message to some object (for example:[[UIColor redColor] CIColor]),
-                     it may throws an exception.
-                     */
-                    @try {
-                        id v = ((id (*)(id, SEL))(void *) objc_msgSend)((id)model, propertyMeta->_getter);
-                        value = ModelToJSONObjectRecursive(v);
-                    }
-                    @catch (NSException *exception) {
-                        // Log the exception and ignore this value.
-                        NSLog(@"%@",exception);
-                    }
+                    id v = ((id (*)(id, SEL))(void *) objc_msgSend)((id)model, propertyMeta->_getter);
+                    value = ModelToJSONObjectRecursive(v);
                     if (value == (id)kCFNull) value = nil;
                 } break;
                 case YYEncodingTypeClass: {
@@ -1287,7 +1277,7 @@ static NSString *ModelDescription(NSObject *model) {
             NSArray *array = (id)model;
             NSMutableString *desc = [NSMutableString new];
             if (array.count == 0) {
-                 return [desc stringByAppendingString:@"[]"];
+                return [desc stringByAppendingString:@"[]"];
             } else {
                 [desc appendFormat:@"[\n"];
                 for (NSUInteger i = 0, max = array.count; i < max; i++) {

+ 1 - 1
YYModelTests/YYTestModelToJSON.m

@@ -109,7 +109,7 @@
     model.shortValue = 4;
     model.array = @[@1,@"2",[NSURL URLWithString:@"https://github.com"]];
     model.set = [NSSet setWithArray:model.array];
-    model.color = [UIColor redColor];
+    model.color = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.5];
     
     NSDictionary *jsonObject = [model yy_modelToJSONObject];
     XCTAssert([jsonObject isKindOfClass:[NSDictionary class]]);