Pārlūkot izejas kodu

change getter and setter's type from NSString to SEL

ibireme 9 gadi atpakaļ
vecāks
revīzija
86db8e1558
3 mainītis faili ar 10 papildinājumiem un 12 dzēšanām
  1. 4 6
      YYModel/NSObject+YYModel.m
  2. 2 2
      YYModel/YYClassInfo.h
  3. 4 4
      YYModel/YYClassInfo.m

+ 4 - 6
YYModel/NSObject+YYModel.m

@@ -357,15 +357,13 @@ static force_inline id YYValueForMultiKeys(__unsafe_unretained NSDictionary *dic
     }
     
     if (propertyInfo.getter) {
-        SEL sel = NSSelectorFromString(propertyInfo.getter);
-        if ([classInfo.cls instancesRespondToSelector:sel]) {
-            meta->_getter = sel;
+        if ([classInfo.cls instancesRespondToSelector:propertyInfo.getter]) {
+            meta->_getter = propertyInfo.getter;
         }
     }
     if (propertyInfo.setter) {
-        SEL sel = NSSelectorFromString(propertyInfo.setter);
-        if ([classInfo.cls instancesRespondToSelector:sel]) {
-            meta->_setter = sel;
+        if ([classInfo.cls instancesRespondToSelector:propertyInfo.setter]) {
+            meta->_setter = propertyInfo.setter;
         }
     }
     

+ 2 - 2
YYModel/YYClassInfo.h

@@ -126,8 +126,8 @@ YYEncodingType YYEncodingGetType(const char *typeEncoding);
 @property (nonatomic, strong, readonly) NSString *typeEncoding;   ///< property's encoding value
 @property (nonatomic, strong, readonly) NSString *ivarName;       ///< property's ivar name
 @property (nonatomic, assign, readonly) Class cls;                ///< may be nil
-@property (nonatomic, strong, readonly) NSString *getter;         ///< getter (nonnull)
-@property (nonatomic, strong, readonly) NSString *setter;         ///< setter (nonnull)
+@property (nonatomic, assign, readonly) SEL getter;               ///< getter (nonnull)
+@property (nonatomic, assign, readonly) SEL setter;               ///< setter (nonnull)
 
 /**
  Creates and returns a property info object.

+ 4 - 4
YYModel/YYClassInfo.m

@@ -205,13 +205,13 @@ YYEncodingType YYEncodingGetType(const char *typeEncoding) {
             case 'G': {
                 type |= YYEncodingTypePropertyCustomGetter;
                 if (attrs[i].value) {
-                    _getter = [NSString stringWithUTF8String:attrs[i].value];
+                    _getter = NSSelectorFromString([NSString stringWithUTF8String:attrs[i].value]);
                 }
             } break;
             case 'S': {
                 type |= YYEncodingTypePropertyCustomSetter;
                 if (attrs[i].value) {
-                    _setter = [NSString stringWithUTF8String:attrs[i].value];
+                    _setter = NSSelectorFromString([NSString stringWithUTF8String:attrs[i].value]);
                 }
             } // break; commented for code coverage in next line
             default: break;
@@ -225,10 +225,10 @@ YYEncodingType YYEncodingGetType(const char *typeEncoding) {
     _type = type;
     if (_name.length) {
         if (!_getter) {
-            _getter = _name;
+            _getter = NSSelectorFromString(_name);
         }
         if (!_setter) {
-            _setter = [NSString stringWithFormat:@"set%@%@:", [_name substringToIndex:1].uppercaseString, [_name substringFromIndex:1]];
+            _setter = NSSelectorFromString([NSString stringWithFormat:@"set%@%@:", [_name substringToIndex:1].uppercaseString, [_name substringFromIndex:1]]);
         }
     }
     return self;