区别?而且!在Swift语言?

区别?而且!在Swift语言?,第1张

概述参见英文答案 > What is the difference between String? and String! (two ways of creating an optional variable)?                                    7个 我在线阅读了很多文章并预订了(Apple),但我无法找出它们之间的区别?而且! Swift语言中的运算符. ove 参见英文答案 > What is the difference between String? and String! (two ways of creating an optional variable)?7个
我在线阅读了很多文章并预订了(Apple),但我无法找出它们之间的区别?而且! Swift语言中的运算符.
overrIDe func tableVIEw(tableVIEw: UItableVIEw!,cellForRowAtIndexPath indexPath: NSIndexPath!) -> UItableVIEwCell!    {    }    overrIDe func numberOfSectionsIntableVIEw(tableVIEw: UItableVIEw?) -> Int {        return 1;    }

在上面的代码中,第一个func声明tableVIEw为!并在第二个函数tableVIEw中声明为?.

根据Apple官方文档:

When working with optional values,you can write ? before operations
like methods,propertIEs,and subscripting. If the value before the ?
is nil,everything after the ? is ignored and the value of the whole
Expression is nil. Otherwise,the optional value is unwrapped,and
everything after the ? acts on the unwrapped value. In both cases,the
value of the whole Expression is an optional value.

Once you’re sure that the optional does contain a value,you can
access its underlying value by adding an exclamation mark (!) to the
end of the optional’s name. The exclamation mark effectively says,“I
kNow that this optional definitely has a value; please use it.” This
is kNown as forced unwrapPing of the optional’s value (…)

Apple Inc.的“Swift编程语言”. iBooks的. https://itun.es/nl/jEUH0.l

总结

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

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

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

原文地址: https://www.outofmemory.cn/web/1051873.html

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

发表评论

登录后才能评论

评论列表(0条)

保存