swift !?

swift !?,第1张

概述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 th

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 jefferyleo 106 2 5 16




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 总结

以上是内存溢出为你收集整理的swift !?全部内容,希望文章能够帮你解决swift !?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1091189.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存