Home  >  Q&A  >  body text

ios - unexpectedly found nil while unwrapping an Optional value

调试时遇到的问题错误,求解决办法

迷茫迷茫2763 days ago502

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 14:55:01

    Looking at this error description, the questioner probably forcibly unpacked the optional variables, right? Forced unpacking must ensure that the variable value is not empty, otherwise an error will be reported. The insurance method is as follows:

    var a:Int?
    if let a1 = a {
        //如果a非空,就会将a的值赋值给a1,然后直接用a1就行了
    }
    

    reply
    0
  • Cancelreply