How does a non optional value obtain a nil value?

后端 未结 4 1301
暖寄归人
暖寄归人 2021-02-13 06:18

The Apple documentation TN2151 says this for a possible cause of a EXC_BREAKPOINT / SIGTRAP:

a non-optional type with a nil valu

4条回答
  •  囚心锁ツ
    2021-02-13 06:56

    I Don't know for sure, but maybe this happens if you force-unwrap (!) an Optional into the Non-Optional variable like this:

    let a : String? = nil
    var x = "hello"
    x = a!
    

    But it's just a guess...

提交回复
热议问题