-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSArray+SFExtension.m
More file actions
122 lines (113 loc) · 3.7 KB
/
NSArray+SFExtension.m
File metadata and controls
122 lines (113 loc) · 3.7 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// NSArray+SFExtension.m
// test
//
// Created by superfeng on 2019/1/14.
// Copyright © 2019年 superfeng. All rights reserved.
//
#import "NSArray+SFExtension.h"
#import <objc/runtime.h>
#import "JRSwizzle.h"
@implementation NSArray (SFExtension)
+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[NSClassFromString(@"__NSArray0") jr_swizzleMethod:@selector(objectAtIndex:) withMethod:@selector(SF_ObjectAtIndex_NSArray0:) error:nil];
[NSClassFromString(@"__NSArrayI") jr_swizzleMethod:@selector(objectAtIndex:) withMethod:@selector(SF_ObjectAtIndex_NSArrayI:) error:nil];
[NSClassFromString(@"__NSArrayM") jr_swizzleMethod:@selector(objectAtIndex:) withMethod:@selector(SF_ObjectAtIndex_NSArrayM:) error:nil];
[NSClassFromString(@"__NSArrayM") jr_swizzleMethod:@selector(removeObjectsInRange:) withMethod:@selector(SF_RemoveObjectsInRange_NSArrayM:) error:nil];
[NSClassFromString(@"__NSSingleObjectArrayI") jr_swizzleMethod:@selector(objectAtIndex:) withMethod:@selector(SF_ObjectAtIndex_NSSingleObjectArrayI:) error:nil];
});
}
- (id)SF_ObjectAtIndex_NSArray0:(NSUInteger)index
{
@autoreleasepool {
if (index >= self.count
|| index < 0
|| !self.count) {
@try {
return [self SF_ObjectAtIndex_NSArray0:index];
} @catch (NSException *exception) {
NSLog(@"%@", [NSThread callStackSymbols]);
return nil;
} @finally {
}
} else {
return [self SF_ObjectAtIndex_NSArray0:index];
}
}
}
- (id)SF_ObjectAtIndex_NSArrayI:(NSUInteger)index
{
@autoreleasepool {
if (index >= self.count
|| index < 0
|| !self.count) {
@try {
return [self SF_ObjectAtIndex_NSArrayI:index];
} @catch (NSException *exception) {
NSLog(@"%@", [NSThread callStackSymbols]);
return nil;
} @finally {
}
} else {
return [self SF_ObjectAtIndex_NSArrayI:index];
}
}
}
- (id)SF_ObjectAtIndex_NSArrayM:(NSUInteger)index
{
@autoreleasepool {
if (index >= self.count
|| index < 0
|| !self.count) {
@try {
return [self SF_ObjectAtIndex_NSArrayM:index];
} @catch (NSException *exception) {
NSLog(@"%@", [NSThread callStackSymbols]);
return nil;
} @finally {
}
} else {
return [self SF_ObjectAtIndex_NSArrayM:index];
}
}
}
- (id)SF_ObjectAtIndex_NSSingleObjectArrayI:(NSUInteger)index
{
@autoreleasepool {
if (index >= self.count
|| index < 0
|| !self.count) {
@try {
return [self SF_ObjectAtIndex_NSSingleObjectArrayI:index];
} @catch (NSException *exception) {
NSLog(@"%@", [NSThread callStackSymbols]);
return nil;
} @finally {
}
} else {
return [self SF_ObjectAtIndex_NSSingleObjectArrayI:index];
}
}
}
- (void)SF_RemoveObjectsInRange_NSArrayM:(NSRange)range
{
@autoreleasepool {
if (range.location < 0
|| range.location >= self.count
|| range.location + range.length >= self.count
|| !self.count) {
@try {
[self SF_RemoveObjectsInRange_NSArrayM:range];
} @catch (NSException *exception) {
NSLog(@"%@", [NSThread callStackSymbols]);
} @finally {
}
} else {
[self SF_RemoveObjectsInRange_NSArrayM:range];
}
}
}
@end