diff --git a/MJExtension/NSObject+MJClass.m b/MJExtension/NSObject+MJClass.m index 9ed7836a..cd987cfe 100644 --- a/MJExtension/NSObject+MJClass.m +++ b/MJExtension/NSObject+MJClass.m @@ -145,27 +145,26 @@ + (void)mj_setupBlockReturnValue:(id (^)(void))block key:(const char *)key MJExtensionSemaphoreSignal } -+ (NSMutableArray *)mj_totalObjectsWithSelector:(SEL)selector key:(const char *)key { ++ (NSMutableArray *)mj_totalObjectsWithSelector:(SEL)selector key:(const char *)key +{ MJExtensionSemaphoreCreate MJExtensionSemaphoreWait NSMutableArray *array = [self mj_classDictForKey:key][NSStringFromClass(self)]; if (array == nil) { // 创建、存储 [self mj_classDictForKey:key][NSStringFromClass(self)] = array = [NSMutableArray array]; - NSMutableSet *classMethodSets = NSMutableSet.set; - [self mj_enumerateAllClasses:^(__unsafe_unretained Class c, BOOL *stop) { - Method method = class_getClassMethod(c, selector); - NSNumber *methodAddress = @((int64_t)(void *)method); - if (method && ![classMethodSets containsObject:methodAddress]) { + + if ([self respondsToSelector:selector]) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" - NSArray *subArray = [c performSelector:selector]; + NSArray *subArray = [self performSelector:selector]; #pragma clang diagnostic pop - if (subArray) { - [array addObjectsFromArray:subArray]; - } - [classMethodSets addObject:methodAddress]; + if (subArray) { + [array addObjectsFromArray:subArray]; } + } + + [self mj_enumerateAllClasses:^(__unsafe_unretained Class c, BOOL *stop) { NSArray *subArray = objc_getAssociatedObject(c, key); [array addObjectsFromArray:subArray]; }]; @@ -173,5 +172,4 @@ + (NSMutableArray *)mj_totalObjectsWithSelector:(SEL)selector key:(const char *) MJExtensionSemaphoreSignal return array; } - @end diff --git a/MJExtensionDemo.xcodeproj/project.pbxproj b/MJExtensionDemo.xcodeproj/project.pbxproj index 3bc315de..49c1c82f 100644 --- a/MJExtensionDemo.xcodeproj/project.pbxproj +++ b/MJExtensionDemo.xcodeproj/project.pbxproj @@ -53,7 +53,6 @@ 2D2DBA832317DBE0005A689E /* MJAd.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D2DBA732317DBDF005A689E /* MJAd.m */; }; 2D2DBA842317DBE0005A689E /* MJExtensionConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D2DBA752317DBDF005A689E /* MJExtensionConfig.m */; }; 2D2DBA852317DBE0005A689E /* MJPerson.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D2DBA772317DBDF005A689E /* MJPerson.m */; }; - 6B431A1D253F2EA900F08763 /* MJElement.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B431A1C253F2EA900F08763 /* MJElement.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -156,8 +155,6 @@ 2D2DBA762317DBDF005A689E /* MJBook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJBook.h; sourceTree = ""; }; 2D2DBA772317DBDF005A689E /* MJPerson.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJPerson.m; sourceTree = ""; }; 2D2DBA872317DCCF005A689E /* PrefixHeader.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrefixHeader.pch; sourceTree = ""; }; - 6B431A1B253F2EA900F08763 /* MJElement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJElement.h; sourceTree = ""; }; - 6B431A1C253F2EA900F08763 /* MJElement.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJElement.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -292,20 +289,18 @@ 2D2DBA602317DBDF005A689E /* MJDog.m */, 2D2DBA6B2317DBDF005A689E /* MJExtensionConfig.h */, 2D2DBA752317DBDF005A689E /* MJExtensionConfig.m */, - 0130EE7E233C56D8008D2386 /* MJFrenchUser.h */, - 0130EE7F233C56D8008D2386 /* MJFrenchUser.m */, 2D2DBA682317DBDF005A689E /* MJPerson.h */, 2D2DBA772317DBDF005A689E /* MJPerson.m */, 2D2DBA622317DBDF005A689E /* MJStatus.h */, 2D2DBA722317DBDF005A689E /* MJStatus.m */, 2D2DBA642317DBDF005A689E /* MJStatusResult.h */, 2D2DBA712317DBDF005A689E /* MJStatusResult.m */, - 2D2DBA6F2317DBDF005A689E /* MJStudent.h */, 2D2DBA662317DBDF005A689E /* MJStudent.m */, + 2D2DBA6F2317DBDF005A689E /* MJStudent.h */, 2D2DBA672317DBDF005A689E /* MJUser.h */, 2D2DBA6E2317DBDF005A689E /* MJUser.m */, - 6B431A1B253F2EA900F08763 /* MJElement.h */, - 6B431A1C253F2EA900F08763 /* MJElement.m */, + 0130EE7E233C56D8008D2386 /* MJFrenchUser.h */, + 0130EE7F233C56D8008D2386 /* MJFrenchUser.m */, ); path = Model; sourceTree = ""; @@ -506,7 +501,6 @@ 2D2DBA842317DBE0005A689E /* MJExtensionConfig.m in Sources */, 2D2DBA7F2317DBE0005A689E /* MJBaseObject.m in Sources */, 2D2DBA7D2317DBE0005A689E /* MJBook.m in Sources */, - 6B431A1D253F2EA900F08763 /* MJElement.m in Sources */, 2D2DBA7A2317DBE0005A689E /* MJDog.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/MJExtensionTests/MJExtensionTests.m b/MJExtensionTests/MJExtensionTests.m index 4dbf6160..af49468f 100644 --- a/MJExtensionTests/MJExtensionTests.m +++ b/MJExtensionTests/MJExtensionTests.m @@ -19,7 +19,6 @@ #import #import "MJFrenchUser.h" #import "MJCat.h" -#import "MJElement.h" @interface MJExtensionTests : XCTestCase @@ -526,16 +525,4 @@ - (void)testLogAllProperties { MJExtensionLog(@"%@", user); } - -#pragma mark 使用 mj_ignoredPropertyNames/mj_allowedPropertyNames 存在继承 -- (void)testIgnoredInheritedProperties { - NSDictionary *dict = @{ - @"count" : @"100", - @"renderName" : @"MJRenderElementName" - }; - MJRenderElement *renderElement = [MJRenderElement mj_objectWithKeyValues:dict]; - XCTAssert(renderElement.count == 0); - XCTAssertFalse(renderElement.renderName); -} - @end diff --git a/MJExtensionTests/Model/MJElement.h b/MJExtensionTests/Model/MJElement.h deleted file mode 100644 index 6048516c..00000000 --- a/MJExtensionTests/Model/MJElement.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// MJElement.h -// MJExtensionTests -// -// Created by libin14 on 2020/10/20. -// Copyright © 2020 MJ Lee. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface MJElement : NSObject - -@property (assign, nonatomic) NSInteger count; - -@end - - -@interface MJRenderElement : MJElement - -@property (copy, nonatomic) NSString *renderName; - -@end - -NS_ASSUME_NONNULL_END diff --git a/MJExtensionTests/Model/MJElement.m b/MJExtensionTests/Model/MJElement.m deleted file mode 100644 index 29aaf083..00000000 --- a/MJExtensionTests/Model/MJElement.m +++ /dev/null @@ -1,26 +0,0 @@ -// -// MJElement.m -// MJExtensionTests -// -// Created by libin14 on 2020/10/20. -// Copyright © 2020 MJ Lee. All rights reserved. -// - -#import "MJElement.h" - -@implementation MJElement - -+ (NSArray *)mj_ignoredPropertyNames { - return @[@"count"]; -} - -@end - -@implementation MJRenderElement - -+ (NSArray *)mj_ignoredPropertyNames { - return @[@"renderName"]; -} - -@end -