@@ -140,35 +140,32 @@ + (NSMutableArray *)mj_properties
140140{
141141 NSMutableArray *cachedProperties = [self mj_propertyDictForKey: &MJCachedPropertiesKey][NSStringFromClass (self )];
142142 if (cachedProperties == nil ) {
143-
144- if (cachedProperties == nil ) {
145- cachedProperties = [NSMutableArray array ];
143+ cachedProperties = [NSMutableArray array ];
144+
145+ [self mj_enumerateClasses: ^(__unsafe_unretained Class c, BOOL *stop) {
146+ // 1.获得所有的成员变量
147+ unsigned int outCount = 0 ;
148+ objc_property_t *properties = class_copyPropertyList (c, &outCount);
146149
147- [self mj_enumerateClasses: ^(__unsafe_unretained Class c, BOOL *stop) {
148- // 1.获得所有的成员变量
149- unsigned int outCount = 0 ;
150- objc_property_t *properties = class_copyPropertyList (c, &outCount);
151-
152- // 2.遍历每一个成员变量
153- for (unsigned int i = 0 ; i<outCount; i++) {
154- MJProperty *property = [MJProperty cachedPropertyWithProperty: properties[i]];
155- // 过滤掉Foundation框架类里面的属性
156- if ([MJFoundation isClassFromFoundation: property.srcClass]) continue ;
157- // 过滤掉`hash`, `superclass`, `description`, `debugDescription`
158- if ([MJFoundation isFromNSObjectProtocolProperty: property.name]) continue ;
159-
160- property.srcClass = c;
161- [property setOriginKey: [self mj_propertyKey: property.name] forClass: self ];
162- [property setObjectClassInArray: [self mj_propertyObjectClassInArray: property.name] forClass: self ];
163- [cachedProperties addObject: property];
164- }
150+ // 2.遍历每一个成员变量
151+ for (unsigned int i = 0 ; i<outCount; i++) {
152+ MJProperty *property = [MJProperty cachedPropertyWithProperty: properties[i]];
153+ // 过滤掉Foundation框架类里面的属性
154+ if ([MJFoundation isClassFromFoundation: property.srcClass]) continue ;
155+ // 过滤掉`hash`, `superclass`, `description`, `debugDescription`
156+ if ([MJFoundation isFromNSObjectProtocolProperty: property.name]) continue ;
165157
166- // 3.释放内存
167- free (properties);
168- }];
158+ property.srcClass = c;
159+ [property setOriginKey: [self mj_propertyKey: property.name] forClass: self ];
160+ [property setObjectClassInArray: [self mj_propertyObjectClassInArray: property.name] forClass: self ];
161+ [cachedProperties addObject: property];
162+ }
169163
170- [self mj_propertyDictForKey: &MJCachedPropertiesKey][NSStringFromClass (self )] = cachedProperties;
171- }
164+ // 3.释放内存
165+ free (properties);
166+ }];
167+
168+ [self mj_propertyDictForKey: &MJCachedPropertiesKey][NSStringFromClass (self )] = cachedProperties;
172169 }
173170
174171 return cachedProperties;
0 commit comments