What is difference between “?” and “!” in Swift?

后端 未结 4 1776
野趣味
野趣味 2020-12-28 16:03

I know what \"?\" and \"!\" mean when I declare variables in Swift. But what do they mean when using these variables? For example, in this code:

var         


        
4条回答
  •  时光说笑
    2020-12-28 16:20

    When you are using ! and the variable is nil it will trigger run time error but if use ? it will fail gracefully. More detail information in apple document

提交回复
热议问题