我因发送到实例 xxxx 的无法识别的选择器而崩溃
但在 LLDB 中,我可以确认该对象应该响应:
(lldb) po [0x7fce2b95d480 class]
XXXViewController
(lldb) e (BOOL)[0x7fce2b95d480 respondsToSelector:@selector(viewDidAppear:)]
(BOOL) $2 = YES
(lldb) e (void)[0x7fce2b95d480 viewDidAppear:YES]
error: Execution was interrupted, reason: breakpoint 1.1.
The process has been returned to the state before expression evaluation.
2015-12-13 18:19:09.316 [13959:7671911] -[XXXViewController viewDidAppear:]: unrecognized selector sent to instance 0x7fce2b95d480
我的调用堆栈符号是:
(lldb) po [NSThread callStackSymbols]
<_NSCallStackArray 0x7fce2f2dea70>(
0 ??? 0x00000001136d9b25 0x0 + 4620917541,
1 xxxxxx 0x000000010095c5b0 main + 0,
2 CoreFoundation 0x0000000103b67d07 ___forwarding___ + 487,
3 CoreFoundation 0x0000000103b67a98 _CF_forwarding_prep_0 + 120,
4 UIKit 0x0000000101607675 -[UIViewController _setViewAppearState:isAnimating:] + 830,
5 UIKit 0x000000010164072e -[UINavigationController viewDidAppear:] + 207,
6 UIKit 0x000000011158ff6e -[UINavigationControllerAccessibility viewDidAppear:] + 46,
7 UIKit 0x0000000101607675 -[UIViewController _setViewAppearState:isAnimating:] + 830,
8 UIKit 0x0000000101607ff8 -[UIViewController _endAppearanceTransition:] + 262,
9 UIKit 0x00000001015d289e -[UIPresentationController transitionDidFinish:] + 827,
10 UIKit 0x00000001017a724f -[_UICurrentContextPresentationController transitionDidFinish:] + 42,
11 UIKit 0x00000001015d5fd5 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 183,
12 UIKit 0x0000000101e68b24 -[_UIViewControllerTransitionContext completeTransition:] + 101,
13 UIKit 0x00000001015cf6b6 -[UITransitionView notifyDidCompleteTransition:] + 252,
14 UIKit 0x00000001015cf3c6 -[UITransitionView _didCompleteTransition:] + 1598,
15 UIKit 0x0000000111583d5c -[UITransitionViewAccessibility _didCompleteTransition:] + 42,
16 UIKit 0x00000001015d1c08 -[UITransitionView _transitionDidStop:finished:] + 104,
17 UIKit 0x00000001014f79df -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 241,
18 UIKit 0x00000001014f7d8e -[UIViewAnimationState animationDidStop:finished:] + 80,
19 UIKit 0x00000001115abaa3 -[UIViewAnimationStateAccessibility animationDidStop:finished:] + 121,
20 QuartzCore 0x00000001040acfa0 _ZN2CA5Layer23run_animation_callbacksEPv + 308,
21 libdispatch.dylib 0x000000010489f49b _dispatch_client_callout + 8,
22 libdispatch.dylib 0x00000001048872af _dispatch_main_queue_callback_4CF + 1738,
23 CoreFoundation 0x0000000103b722e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9,
24 CoreFoundation 0x0000000103b338a9 __CFRunLoopRun + 2073,
25 CoreFoundation 0x0000000103b32e08 CFRunLoopRunSpecific + 488,
26 GraphicsServices 0x00000001068f5ad2 GSEventRunModal + 161,
27 UIKit 0x000000010146f30d UIApplicationMain + 171,
28 xxxx 0x000000010095c61f main + 111,
29 libdyld.dylib 0x00000001048d392d start + 1
编辑完整性
2015-12-13 18:28:55.928 XXXX[13959:7671911] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[XXXViewController viewDidAppear:]: unrecognized selector sent to instance 0x7fce2b95d480'
*** First throw call stack:
(
0 CoreFoundation 0x0000000103c11f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010368bdeb objc_exception_throw + 48
2 CoreFoundation 0x0000000103c1a56d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000103b67d07 ___forwarding___ + 487
4 CoreFoundation 0x0000000103b67a98 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000101607675 -[UIViewController _setViewAppearState:isAnimating:] + 830
6 UIKit 0x000000010164072e -[UINavigationController viewDidAppear:] + 207
7 UIKit 0x000000011158ff6e -[UINavigationControllerAccessibility viewDidAppear:] + 46
8 UIKit 0x0000000101607675 -[UIViewController _setViewAppearState:isAnimating:] + 830
9 UIKit 0x0000000101607ff8 -[UIViewController _endAppearanceTransition:] + 262
10 UIKit 0x00000001015d289e -[UIPresentationController transitionDidFinish:] + 827
11 UIKit 0x00000001017a724f -[_UICurrentContextPresentationController transitionDidFinish:] + 42
12 UIKit 0x00000001015d5fd5 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 183
13 UIKit 0x0000000101e68b24 -[_UIViewControllerTransitionContext completeTransition:] + 101
14 UIKit 0x00000001015cf6b6 -[UITransitionView notifyDidCompleteTransition:] + 252
15 UIKit 0x00000001015cf3c6 -[UITransitionView _didCompleteTransition:] + 1598
16 UIKit 0x0000000111583d5c -[UITransitionViewAccessibility _didCompleteTransition:] + 42
17 UIKit 0x00000001015d1c08 -[UITransitionView _transitionDidStop:finished:] + 104
18 UIKit 0x00000001014f79df -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 241
19 UIKit 0x00000001014f7d8e -[UIViewAnimationState animationDidStop:finished:] + 80
20 UIKit 0x00000001115abaa3 -[UIViewAnimationStateAccessibility animationDidStop:finished:] + 121
21 QuartzCore 0x00000001040acfa0 _ZN2CA5Layer23run_animation_callbacksEPv + 308
22 libdispatch.dylib 0x000000010489f49b _dispatch_client_callout + 8
23 libdispatch.dylib 0x00000001048872af _dispatch_main_queue_callback_4CF + 1738
24 CoreFoundation 0x0000000103b722e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
25 CoreFoundation 0x0000000103b338a9 __CFRunLoopRun + 2073
26 CoreFoundation 0x0000000103b32e08 CFRunLoopRunSpecific + 488
27 GraphicsServices 0x00000001068f5ad2 GSEventRunModal + 161
28 UIKit 0x000000010146f30d UIApplicationMain + 171
29 XXX 0x000000010095c61f main + 111
30 libdyld.dylib 0x00000001048d392d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
编辑2:一个更完整的例子:(为缺乏格式道歉,所以编辑横幅不起作用)
我正在UIViewController
通过@steipete 添加有关使用库的方面
https://github.com/steipete/Aspects
```
#import "Aspects.h"
Class baseClass = [self baseClass:class selector:selector];
__weak __typeof__(self) weakSelf = self;
id aspect = [baseClass aspect_hookSelector:selector withOptions:AspectPositionAfter usingBlock:^(id <AspectInfo> info) {
__typeof__(weakSelf) strongSelf = weakSelf;
id instance = info.instance;
[strongSelf didCall:[instance class] selector:selector info:info signiture:signiture];
} error:err];
```