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

后端 未结 4 1806
野趣味
野趣味 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:23

    Both symbols ! and ? used for optionals. We should have to use !, when we make sure option type variable has value at a time and we need to take action on it.Otherwise It will crash if variable value is nil.And if you are using ?, Application will not crash in nil case.

    You can follow this link for more information:- https://www.youtube.com/watch?v=twBfiKsbHP8

提交回复
热议问题