How does a non optional value obtain a nil value?

后端 未结 4 1303
暖寄归人
暖寄归人 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:40

    Contrived, but possible:

    class C {}
    
    let x: C? = nil
    let y: C = unsafeBitCast(x, to: C.self)
    
    print(y) // boom
    

提交回复
热议问题