综合出现NSScanner: nil string argument libc++abi.dylib: terminat错误的解决方案
在开发中出现了这个错误,断点查找很久,没找到问题所在的代码,google下,发现了下面这几点会产生这个错误:
- 首先,顾名思义,错误原因是我们在调用某个方法的时候,传入了一个空字符串(注意区别于字符串内容为空)作为方法参数。
- 对某一个空数组使用objectAtIndex方法。不会报数组越界的错,而是NSScanner: nil string argument。
经过检查,我代码中如果字符串赋值,我一般都对nil做了一定处理,用@""代替,也未有数组越界,但是还是报这样的错误。
现在的信息点是libc++abi.dylib,这个库到底是做什么的?从后缀看,是一个动态库,那么会不会是因为发生了一些动态错误?而按经验来看,一般的动态错误基本是因为动态类型错误引起,在object-c语言中,会发生动态类型错误的可能基本存在于不可变类型与可变类型之间的转换,那么我们的查错范围将优先限制在不可变类型与可变类型转换上,是否我们对一个不可变类型进行了修改操作?当然,编译器没有那么傻,如果直接对一个不可变类型进行修改操作,是会直接报错的,那么就剩下另一种可能,程序将一个不可变类型赋值给可变类型,然后对可变类型进行了修改操作,这样可以通过静态检查,但是动态运行的时候,就会发生类型错误。基于以上分析,我们可以跟踪断点,会发现程序在对mutable对象进行add、set等操作时挂掉,而这个对象实际上赋值的是一个不可变对象。常见的情况是把一个NSArray对象赋值给一个NSMutableArray对象,然后进行了delete、add等修改操作,或者把一个NSDictionary对象赋值给一个NSMutableDictionary对象,然后进行了set等操作。
这是从http://www.itnose.net/detail/6196671.html里面得来的方案,经过排查,代码表面上也未有这样的错误。
然后找到最后崩溃处的断点代码如下:
NSDictionary *orderDict = [notification userInfo];
self.selectedOrderDict = orderDict;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.selectedRow inSection:0];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:@[indexPath], nil] withRowAnimation:UITableViewRowAnimationNone];
灵机一动,其实是实在不知道怎么改了,于是改成了下面的代码,然后编译,运行,既然可以了。。。。。。
NSDictionary *orderDict = [notification userInfo];
self.selectedOrderDict = orderDict;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.selectedRow inSection:0];
NSMutableArray *tmpArray = [NSMutableArray array];
[tmpArray addObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:tmpArray withRowAnimation:UITableViewRowAnimationNone];
不解,既然这样就可以了,可是从代码层次、逻辑层次来说,这两种写法应该是一样的,难道是这个借口需要的是可变的数组?于是打开里面的接口,发现是这样的:
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);
当时我的心情是崩溃的,尼玛,那啥意思,于是有了下面的测试:
NSDictionary *orderDict = [notification userInfo];
self.selectedOrderDict = orderDict;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.selectedRow inSection:0];
// NSMutableArray *tmpArray = [NSMutableArray array];
// [tmpArray addObject:indexPath];
// [self.tableView reloadRowsAtIndexPaths:tmpArray withRowAnimation:UITableViewRowAnimationNone];
NSArray *tmpArray = @[indexPath];
[self.tableView reloadRowsAtIndexPaths:tmpArray withRowAnimation:UITableViewRowAnimationNone];
这样也是不崩溃的......
好吧,到这,还是没发现错误原因,然后回去仔细看看面前的代码,发现
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.selectedRow inSection:0];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:@[indexPath], nil] withRowAnimation:UITableViewRowAnimationNone];
indexPath本身就是个对象了,而我还用NSValues包装它,放进去,肯定不能解析而崩溃啊......
综合出现NSScanner: nil string argument libc++abi.dylib: terminat错误的解决方案的更多相关文章
- oc for in 的时候nsscanner: nil string argument
今天偶然发现,oc for in 动态的给一数组加东西,然后嵌套for in 会报nsscanner: nil string argument. 换成for循环就好了,暂时还没找到原因
- 新浪微博分享出现libc++abi.dylib: terminating with uncaught exception of type NSException微博微信SDK运行编译报错
SDK出现libc++abi.dylib: terminating with uncaught exception of type NSException 的问题: 解决方法 结合 # 监测bug( ...
- iOS - libc++abi.dylib: terminate_handler unexpectedly threw an exception
代码出现crash,报错:libc++abi.dylib: terminate_handler unexpectedly threw an exception 当我们很明确是某一块代码执行导致了错误, ...
- 如何调试libc++abi.dylib handler threw exception错误
From:http://blog.csdn.net/naruto_ku/article/details/8779203 在进行iOS开发时,偶尔会碰到libc++abi.dylib handler t ...
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
说法一: 我们在运行xcode工程时,有时候会遇到”libc++abi.dylib: terminate_handler unexpectedly threw an exception”错误,app莫 ...
- libc++abi.dylib handler threw exception
在iOS开发时,有时候遇到libc++abi.dylib handler threw exception这样的异常, 虽然在断点出加上了All Exceptions,也断到相应的代码了,但是没打印对 ...
- mac python3 conda pytorch出错:libc++abi.dylib: terminating with uncaught exception of type NSException
mac 10.14/ conda/python 3.7环境下运行神经网络例子出现错误: -- :::] -[NSApplication _setup:]: unrecognized selector ...
- IOS Exception 1(libc++abi.dylib: terminating with uncaught exception of type NSException)
2014-08-05 22:18:46.455 SwiftUI[1329:40871] -[_TtC7SwiftUI14MViewControler clickMe]: unrecognized se ...
- libc++abi.dylib`__cxa_throw: 使用[AVAudioPlayer play]会产生__cxa_throw异常
libc++abi.dylib`__cxa_throw: 使用[AVAudioPlayer play]会产生__cxa_throw异常 开发中遇到一个奇怪的异常.我调用AVAudioPlayer pl ...
随机推荐
- Ant压缩与解压缩
package com.test.utils; import java.io.File; import java.io.FileOutputStream; import java.io.InputSt ...
- 如何用STAF进行自动化测试分布式运行
本文的目的在于引导读者去了解STAF及如何调用其接口去实现自动化测试的分布式动行. 提到分布式运行,很多人想到了Jenkins,Jenkins里面有个node插件,可以去分派任务给slave,Jenk ...
- C语言open()函数:打开文件函数(转)
相关函数:read, write, fcntl, close, link, stat, umask, unlink, fopen 头文件:#include <sys/types.h> ...
- TensorFlow Google大会总结
一.概述 介绍TPU,需要使用XLA编译,否则没有做内部优化,无法达到加速的效果: TPU相关的性能分析器: 二.新版本的输入库 之前TensorFlow的输入方式: feed_dict: 太过于低效 ...
- golang学习 ---并发获取多个URL
package main import ( "fmt" "io" "io/ioutil" "net/http" &quo ...
- python ---Pandas时间序列:生成指定范围的日期
引入包 import pandas as pd import numpy as np 1.生成指定范围的日期 print pd.date_range('11/1/2018','11/9/2018') ...
- xtrabackup-工作原理
数据备份 xtrabackup是基于innodb的crash恢复功能之上的.它会拷贝innodb数据文件(这会导致数据不一致的),然后对文件执行crash恢复使其一致. 因为innodb维护了redo ...
- Debian本地镜像长时间不更新
一.执行apt-get update 使用一个长期未更新的本地源,得到错误的提示: Release file for ... is expired. Updates for this reposito ...
- 转:zTree树控件扩展篇:巧用zTree控件实现文本框输入关键词自动模糊查找zTree树节点实现模糊匹配下拉选择效果
是否可以借助于zTree实现文本框输入关键词自动模糊匹配zTree下拉树,然后选择下拉树内节点显示在文本框内且隐藏下拉树. 看到这个需求脑子里头大致已经想到了要如何实现这样一个需求,当时是限于时间问题 ...
- 发一些靠谱的招聘网站(含ios)
近日整理一些 招聘网站 , 欢迎大家 推荐 http://www.zhaopin.com 智联,貌似这货上市了.. http://www.51job.com 51job 还行 大街就不提了.0. ...