Find line matching error in Xcode debugger
2 answers
Look in the lines below this,
you should have a backtrace of the methods that you and the system are executing.
There you should find the name of the method in which it occurred.
I just took an existing project and added a similar crash and goal to illustrate this.
My method is -
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.contacts = [NSMutableArray arrayWithArray: [ARContact loadContacts]];
NSLog(@"%@", self.contacts[100]); // Index 100 is outside of the array scope
....
}
Crash console log (at the bottom of Xcode)
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 100 beyond bounds for empty array'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101a87495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001007ec99e objc_exception_throw + 43
2 CoreFoundation 0x0000000101a2d745 -[__NSArrayM objectAtIndex:] + 213
3 PhoneBookApp 0x0000000100001f95 -[ViewController viewWillAppear:] + 261
4 UIKit 0x0000000100b1adb5 -[UIViewController _setViewAppearState:isAnimating:] + 422
5 UIKit 0x0000000100b38c4d -[UINavigationController _startTransition:fromViewController:toViewController:] + 707
Here you can see things reversed as they occur (meaning 0 is the last thing to run, 1 before that, etc.).
If you look at the numbers 3 and 4, you can see that a method call appears before the failure NSArray
objectAtIndex:
(line 3),
and this method is called from viewWillAppear:
(line 4).
0
source to share