How does a non optional value obtain a nil value?

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

    Consider something like this in Objective-C bridged to Swift:

    - (NSObject * _Nonnull)someObject {
        return nil;
    }
    

    The function is annotated as _Nonnull, but will return nil. This bridged as a non-optional object to Swift and will crash.

提交回复
热议问题