Skip to content

Commit 0341b76

Browse files
authored
Fix DelegateProxy bug (#32)
1 parent 7ba9df5 commit 0341b76

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Sources/Runtime/ObjcDelegateProxy.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,23 @@
1010
#import "include/ObjcDelegateProxy.h"
1111
#import <objc/runtime.h>
1212

13-
static NSSet <NSValue *> *selectors;
13+
#define OBJECT_VALUE(object) [NSValue valueWithNonretainedObject:(object)]
14+
15+
static NSMutableDictionary<NSValue *, NSSet<NSValue *> *> *allSelectors;
1416

1517
@implementation ObjcDelegateProxy
1618

1719
- (NSSet *)selectors {
18-
return selectors;
20+
return allSelectors[OBJECT_VALUE(self.class)];
1921
}
2022

2123
+ (void)initialize
2224
{
2325
@synchronized (ObjcDelegateProxy.class) {
24-
selectors = [self selectorsOfClass:self
26+
if (!allSelectors) {
27+
allSelectors = [NSMutableDictionary new];
28+
}
29+
allSelectors[OBJECT_VALUE(self)] = [self selectorsOfClass:self
2530
withEncodedReturnType:[NSString stringWithFormat:@"%s", @encode(void)]];
2631
}
2732
}
@@ -31,7 +36,7 @@ - (BOOL)respondsToSelector:(SEL _Nonnull)aSelector {
3136
}
3237

3338
- (BOOL)canRespondToSelector:(SEL _Nonnull)selector {
34-
for (id current in selectors) {
39+
for (id current in allSelectors[OBJECT_VALUE(self.class)]) {
3540
if (selector == (SEL) [current pointerValue]) {
3641
return true;
3742
}

0 commit comments

Comments
 (0)