加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift !?

发布时间:2020-12-14 02:39:35 所属栏目:百科 来源:网络整理
导读:Actually what is the "!" in swift? I know it is represent NOT meaning,but how come in this case it uses like this? Anyone can explain it to me,I'm new to Swift programming language. share improve this answer answered Apr 4 at 5:21 jefferyl

Actually what is the "!" in swift? I know it is represent NOT meaning,but how come in this case it uses like this? Anyone can explain it to me,I'm new to Swift programming language.

share improve this answer




Swift uses!in several distinct ways. The one used in these answers is to force unwrap an Optional value. An Optional type is a regular type,e.g.String,which can also beniland is writtenString?. If you have a value of typeString?and you want to unwrap it to get a value of typeStringthen you use!on the value. In other words,ifx: String?you can writex!to get the plainStringvalue wrapped up by the optional. This only works if you know the value is notnil,otherwise you will get a runtime exception. The!is to signify the potential danger.rokobSep 30 at 5:06






Swift uses!is to signify the potential danger. rokob Sep 30 at 5:06

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读