iOS开发问题—— [__NSCFString charValue]

报错详情

2016-05-10 14:14:50.067 xxx[1352:130890] -[__NSCFString charValue]: unrecognized selector sent to instance 0x176bc6a0

2016-05-10 14:14:50.068 xxx[1352:130890] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString charValue]: unrecognized selector sent to instance 0x176bc6a0'

*** First throw call stack:

(0x249b1fef 0x32c63c8b 0x249b7409 0x249b5327 0x248e4e78 0x2568e577 0x2564621f 0x256460e1 0x256c3bab 0x72fdd 0x73041 0x854b3 0x85981 0x280d48bf 0x280d3dc7 0x280d3c09 0x280d3a3d 0x282d4027 0x282d3bb9 0x84a3b 0x28006b8f 0x280b1955 0x280b187d 0x280b0dfb 0x280b0b2b 0x280b0895 0x280b0829 0x28004023 0x27a24d99 0x27a205cd 0x27a20455 0x27a1fdf1 0x27a1fbdf 0x27ffc23b 0x24977fed 0x249756ab 0x24975ab3 0x248c2201 0x248c2013 0x2c1a1201 0x28066a59 0x9ebe5 0x331efaaf)

libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb)

问题描述

  在iPhone 5s以上设备都没有问题,iPad设备暂没有测试

  使用iPhone 5测试,加载问题所在view时,App crash。

原因排查和解决

  1. 首先,经过逐一debug定位[__NSCFString charValue]问题所在具体代码位置

  2. 经排查,是在读取字典的最后一项时出错,且没有得到内容

  3. 从stackoverflow上查询该类问题,有个回答说由于CPU位数32/64bit 差别,bool类型的默认值范围有所不同。详细说明见  

http://stackoverflow.com/questions/31408909/nscfstring-charvalue-unrecognized-selector-sent-to-instance

http://stackoverflow.com/questions/31267325/bool-with-64-bit-on-ios/31270249#31270249

  4. 我的问题虽然和上述描述不完全一致,但是已足够指明问题原因,如下图,有两项使能开关值被设置为了String类型,但它们实际上是用来控制我的自定义cell中的slider和switch要不要被启用的开关。

  

  5. 改为以下BOOL类型之后,问题OK

  

总结

  这个问题犯的比较弱智,但是由于不同平台的不同表现,问题排查不容易想到数据类型的问题上;

  另外,正因为这个原因,通过此问题可以继续去扩展一些不同位数的处理器可能会带来的差别,顺便探究一番也算值得

 

posted on 2016-05-10 15:55  Rosa.Bai  阅读(470)  评论(0)    收藏  举报