Skip to content

Commit 4586940

Browse files
author
李杰
committed
fix kvo crash #33
1 parent a29d40b commit 4586940

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

JJException/Source/MRC/NSObject+KVOCrash.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ + (void)jj_swizzleKVOCrash{
157157
swizzleInstanceMethod([self class], @selector(addObserver:forKeyPath:options:context:), @selector(hookAddObserver:forKeyPath:options:context:));
158158
swizzleInstanceMethod([self class], @selector(removeObserver:forKeyPath:), @selector(hookRemoveObserver:forKeyPath:));
159159
swizzleInstanceMethod([self class], @selector(removeObserver:forKeyPath:context:), @selector(hookRemoveObserver:forKeyPath:context:));
160+
//Swizzle kvo dealloc
161+
swizzleInstanceMethod([self class], @selector(dealloc), @selector(kvo_hookDealloc));
160162
}
161163

162164
- (void)hookAddObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context{
@@ -182,9 +184,6 @@ - (void)hookAddObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath opti
182184
[objectContainer setWhichObject:self];
183185
objc_setAssociatedObject(self, &DeallocKVOKey, objectContainer, OBJC_ASSOCIATION_RETAIN);
184186
[objectContainer release];
185-
186-
//Swizzle kvo dealloc
187-
[self jj_swizzleInstanceMethod:@selector(dealloc) withSwizzleMethod:@selector(kvo_hookDealloc)];
188187
}
189188

190189
if (![objectContainer checkKVOItemExist:item]) {

0 commit comments

Comments
 (0)