Skip to content

Commit a29d40b

Browse files
author
李杰
committed
add hook API
1 parent bdfa8ed commit a29d40b

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

JJExceptionHookAPI.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
* NSObject(UnrecognizedSelectorHook)
3+
4+
```
5+
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
6+
- (void)forwardInvocation:(NSInvocation *)anInvocation;
7+
```
8+
9+
* NSObject(KVOCrash)
10+
11+
```
12+
- (void) addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath
13+
options:(NSKeyValueObservingOptions)options context:(void *)context;
14+
- (void) removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath;
15+
- (void) removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath context:(nullable void *)context;
16+
```
17+
18+
* NSString
19+
20+
```
21+
+ (NSString*) stringWithUTF8String:(const char *)nullTerminatedCString;
22+
+ (nullable instancetype) stringWithCString:(const char *)cString encoding:(NSStringEncoding)enc;
23+
- (nullable instancetype) initWithCString:(const char *)nullTerminatedCString encoding:(NSStringEncoding)encoding;
24+
- (NSString *)substringFromIndex:(NSUInteger)from;
25+
- (NSString *)substringToIndex:(NSUInteger)to;
26+
- (NSString *)substringWithRange:(NSRange)range;
27+
```
28+
29+
* NSMutableString
30+
31+
```
32+
- (nullable instancetype) safeInitWithCString:(const char *)nullTerminatedCString encoding:(NSStringEncoding)encoding;
33+
- (void) appendString:(NSString *)aString;
34+
- (void) insertString:(NSString *)aString atIndex:(NSUInteger)loc;
35+
- (void) deleteCharactersInRange:(NSRange)range;
36+
- (NSString *)stringByAppendingString:(NSString *)aString;
37+
```
38+
39+
* NSArray
40+
41+
```
42+
+ (instancetype) arrayWithObject:(id)anObject;
43+
- (id) objectAtIndex:(NSUInteger)index;
44+
- (NSArray<ObjectType> *)subarrayWithRange:(NSRange)range;
45+
- (id) objectAtIndexedSubscript:(NSInteger)index
46+
```
47+
48+
* NSMutableArray
49+
50+
```
51+
- (void) addObject:(id)anObject;
52+
- (id) objectAtIndex:(NSUInteger)index;
53+
- (void) insertObject:(id)anObject atIndex:(NSUInteger)index;
54+
- (void) removeObjectAtIndex:(NSUInteger)index;
55+
- (void) replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject;
56+
- (void) removeObjectsInRange:(NSRange)range;
57+
```
58+
59+
* NSDictionary
60+
61+
```
62+
+ (instancetype) dictionaryWithObject:(id)object forKey:(id)key;
63+
- (id) objectForKey:(id)aKey;
64+
```
65+
66+
* NSMutableDictionary
67+
68+
```
69+
- (void) setObject:(id)anObject forKey:(id)aKey;
70+
- (void) removeObjectForKey:(id)aKey;
71+
```
72+
73+
* NSSet
74+
75+
```
76+
+ (instancetype)setWithObject:(id)object;
77+
```
78+
79+
* NSMutableSet
80+
81+
```
82+
- (void) addObject:(id)object;
83+
- (void) removeObject:(id)object;
84+
```

JJExceptionPrinciple.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ KVO在以下情况会导致闪退:
195195
* 保护key不存在的情况
196196
* 保护重复添加的情况
197197

198-
在开始KVO是采用AssociatedObject释放原理来处理那些忘记keyPath,这里有个问题就是如果开发者重写dealloc,并清理自己的keyPath,会导致AssociatedObject释放时,assgin的类产生野指针,
198+
在开始KVO是采用AssociatedObject释放原理来处理那些忘记keyPath,这里有个问题就是如果开发者重写dealloc,并清理自己的keyPath,会导致AssociatedObject释放时,target产生野指针.
199199

200200
所以在没找到更好的办法,只能Swizzle dealloc方法,先清理kvo数据,再执行origin dealloc,不过这样就有个细节做不到,无法提示那些keyPath忘记清理.
201201

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ func handleCrashException(_ exceptionMessage: String, extraInfo info: [AnyHashab
160160
}
161161
```
162162

163+
> Hook的API列表
164+
165+
[HookAPI](https://github.com/jezzmemo/JJException/blob/master/JJExceptionHookAPI.md)
166+
163167

164168
## TODO(大家记得给我星哦)
165169
* 收集更多常见异常

0 commit comments

Comments
 (0)