[关闭]
@buoge 2017-07-17T15:32:30.000000Z 字数 961 阅读 923

动态赋值变量 统一设置为Optional比较保险

iOS 程序构建


bugly 崩溃报告,字面意思理解是,数组删除那里出了错,而且非可选,被设置为可选了,想了想有可能是 list 这个对象,刚开始被设置为非空类型,如遇特殊的生命周期,导致其为nil,就会出现这等情况

  1. 0 libswiftCore.dylib __TTSfq4n_n_d_d_n___TFs18_fatalErrorMessageFTVs12StaticStringS_4fileS_4lineSu5flagsVs6UInt32_Os5Never + 120
  2. 1 libswiftCore.dylib __TTSfq4n_n_d_d_n___TFs18_fatalErrorMessageFTVs12StaticStringS_4fileS_4lineSu5flagsVs6UInt32_Os5Never + 120
  3. 2 libswiftCore.dylib __TFVs12_ArrayBuffer10getElementfTSi20wasNativeTypeCheckedSb_x
  4. 3 libswiftCore.dylib __TFSag9subscriptFSix + 100
  5. 4 libswiftCore.dylib __TFVs15ContiguousArray6removefT2atSi_x_merged + 56
  6. 5 zaozuo deleteCombinationCallBack (CartBaseController.swift:903)
  7. 如果Swift代码在运行时发现一个意外的情况时,也会以该异常类型结束程序。例如:
  8. 为一个非可选(non-optional)类型被赋值nil
  9. 一个有问题的强制类型转换

// bugly.qq.com/v2/crash-reporting/crashes/f98c73468f/1219?pid=2
// libswiftCore.dylib__TFVs15ContiguousArray6removefT2atSi_x_merged + 56
// 凡事涉及动态赋值的变量,还是设置为 optional 比较保险,optional 会对其进行判断,不至于崩溃

if (list != nil && list.count >= selectIndex) {
    list.remove(at: selectIndex)
}
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注