From 452dfd5997c8a7af4655ef3a6d700d2b102aa43c Mon Sep 17 00:00:00 2001 From: shangxiaonan Date: Thu, 28 Mar 2019 18:03:36 +0800 Subject: [PATCH] fix deregister tracker --- Aspects.m | 11 +++++++---- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 Aspects.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Aspects.m b/Aspects.m index c907066..e0bb41b 100644 --- a/Aspects.m +++ b/Aspects.m @@ -72,7 +72,7 @@ - (id)initWithTrackedClass:(Class)trackedClass; @property (nonatomic, strong) NSMutableSet *selectorNames; @property (nonatomic, strong) NSMutableDictionary *selectorNamesToSubclassTrackers; - (void)addSubclassTracker:(AspectTracker *)subclassTracker hookingSelectorName:(NSString *)selectorName; -- (void)removeSubclassTracker:(AspectTracker *)subclassTracker hookingSelectorName:(NSString *)selectorName; +- (BOOL)removeSubclassTracker:(AspectTracker *)subclassTracker hookingSelectorName:(NSString *)selectorName; - (BOOL)subclassHasHookedSelectorName:(NSString *)selectorName; - (NSSet *)subclassTrackersHookingSelectorName:(NSString *)selectorName; @end @@ -657,11 +657,13 @@ static void aspect_deregisterTrackedSelector(id self, SEL selector) { do { AspectTracker *tracker = swizzledClassesDict[currentClass]; if (subclassTracker) { - [tracker removeSubclassTracker:subclassTracker hookingSelectorName:selectorName]; + BOOL empty = [tracker removeSubclassTracker:subclassTracker hookingSelectorName:selectorName]; + if (!empty) + break; } else { [tracker.selectorNames removeObject:selectorName]; } - if (tracker.selectorNames.count == 0 && tracker.selectorNamesToSubclassTrackers) { + if (tracker.selectorNames.count == 0 && tracker.selectorNamesToSubclassTrackers.count == 0) { [swizzledClassesDict removeObjectForKey:currentClass]; } subclassTracker = tracker; @@ -693,12 +695,13 @@ - (void)addSubclassTracker:(AspectTracker *)subclassTracker hookingSelectorName: } [trackerSet addObject:subclassTracker]; } -- (void)removeSubclassTracker:(AspectTracker *)subclassTracker hookingSelectorName:(NSString *)selectorName { +- (BOOL)removeSubclassTracker:(AspectTracker *)subclassTracker hookingSelectorName:(NSString *)selectorName { NSMutableSet *trackerSet = self.selectorNamesToSubclassTrackers[selectorName]; [trackerSet removeObject:subclassTracker]; if (trackerSet.count == 0) { [self.selectorNamesToSubclassTrackers removeObjectForKey:selectorName]; } + return trackerSet.count == 0; } - (NSSet *)subclassTrackersHookingSelectorName:(NSString *)selectorName { NSMutableSet *hookingSubclassTrackers = [NSMutableSet new]; diff --git a/Aspects.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Aspects.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Aspects.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + +