-
Notifications
You must be signed in to change notification settings - Fork 4
/
NSNumber+AvoidMTLModelCrash.m
45 lines (37 loc) · 1.15 KB
/
NSNumber+AvoidMTLModelCrash.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#import "NSNumber+AvoidMTLModelCrash.h"
#import "JRSwizzle.h"
static NSString *__checkString = @"";
@implementation NSNumber (AvoidMTLModelCrash)
+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self avoidMTLModelCrash];
});
}
+ (void)avoidMTLModelCrash
{
[self jr_swizzleMethod:@selector(respondsToSelector:) withMethod:@selector(swizzle_respondsToSelector:) error:nil];
[self jr_swizzleMethod:@selector(forwardingTargetForSelector:) withMethod:@selector(swizzle_forwardingTargetForSelector:) error:nil];
}
- (BOOL)swizzle_respondsToSelector:(SEL)aSelector
{
if ([self swizzle_respondsToSelector:aSelector]) {
return YES;
}
if ([__checkString respondsToSelector:aSelector]) {
return YES;
}
return [super respondsToSelector:aSelector];
}
- (id)swizzle_forwardingTargetForSelector:(SEL)aSelector
{
if ([self swizzle_forwardingTargetForSelector:aSelector]) {
return self;
}
if ([__checkString respondsToSelector:aSelector]) {
return [NSString stringWithFormat:@"%@", self];
}
return [super forwardingTargetForSelector:aSelector];
}
@end