ios 定位问题代码的方法

1.定位数组越界代码的位置

NSArray *array1=@[@"1",@"2"];
NSString *s1=array1[2];


143509_a33a_2360054.png


这个是经常遇到的问题

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
*** First throw call stack:
(
	0   CoreFoundation                      0x034d1a14 __exceptionPreprocess + 180
	1   libobjc.A.dylib                     0x02b54e02 objc_exception_throw + 50
	2   CoreFoundation                      0x033a9a4e -[__NSArrayI objectAtIndex:] + 206
	3   ScanCode                            0x000bca53 -[NSArray(Debug) objectAtIndexDebug:] + 691
	4   CoreFoundation                      0x034161d8 -[NSArray objectAtIndexedSubscript:] + 40
	5   ScanCode                            0x00162dcb -[AppDelegate application:didFinishLaunchingWithOptions:] + 827
	6   UIKit                               0x00dee172 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 337
	7   UIKit                               0x00def5a0 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3863
	8   UIKit                               0x00df6cd6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1989
	9   UIKit                               0x00e1bee5 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke3218 + 68
	10  UIKit                               0x00df3966 -[UIApplication workspaceDidEndTransaction:] + 163
	11  FrontBoardServices                  0x07ca9c76 __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
	12  FrontBoardServices                  0x07ca974d __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
	13  FrontBoardServices                  0x07cc7173 -[FBSSerialQueue _performNext] + 184
	14  FrontBoardServices                  0x07cc75aa -[FBSSerialQueue _performNextFromRunLoopSource] + 52
	15  FrontBoardServices                  0x07cc68a6 FBSSerialQueueRunLoopSourceHandler + 33
	16  CoreFoundation                      0x033eb6ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
	17  CoreFoundation                      0x033e138b __CFRunLoopDoSources0 + 523
	18  CoreFoundation                      0x033e07a8 __CFRunLoopRun + 1032
	19  CoreFoundation                      0x033e00e6 CFRunLoopRunSpecific + 470
	20  CoreFoundation                      0x033dfefb CFRunLoopRunInMode + 123
	21  UIKit                               0x00df3206 -[UIApplication _run] + 540
	22  UIKit                               0x00df8bfa UIApplicationMain + 160
	23  ScanCode                            0x001657ea main + 138
	24  libdyld.dylib                       0x0427ea21 start + 1
	25  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)


在调试的po命令里面输入 image lookup -a 内存地址 就可以找到报错代码的位置

(lldb) image lookup -a 0x00162dcb
      Address: ScanCode[0x000a8dcb] (ScanCode.__TEXT.__text + 681771)
      Summary: ScanCode`-[AppDelegate application:didFinishLaunchingWithOptions:] 
      + 827 at AppDelegate.m:34


就知道是在AppDelegate的34行


2 普通代码错误


可以用symbolic断点viewDidLoad这样在每个控制器返回都会停一下


结合NSLog宏输出当前的文件名和行数来定位会变得很容易 


3 UI相关问题

view debug

必要时给view加背景色


4 网络相关问题

检查网址和参数

Charles 分析网络请求的内容


http 测试工具


如果是get请求,有时候可以直接用浏览器打开链接进行测试 


5 集成第三方库的问题

参考官方说明或者其它人的demo和教程

参考官方的demo


6 毫无头绪的问题

尽量描述清楚,发帖求助,然后暂时不处理


因为毫无头绪还在继续研究是浪费时间的行为,除非你的项目其它部分都已经完成。或者你在紧急修复bug,否则都不应该在没有头绪的情况下处理bug


转载于:https://my.oschina.net/u/2360054/blog/606844

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值