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

区别?而且!在Swift语言?

发布时间:2020-12-14 05:49:09 所属栏目:百科 来源:网络整理
导读:参见英文答案 What is the difference between String? and String! (two ways of creating an optional variable)?7个 我在线阅读了很多文章并预订了(Apple),但我无法找出它们之间的区别?而且! Swift语言中的运算符. override func tableView(tableView:
参见英文答案 > 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

(编辑:李大同)

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

    推荐文章
      热点阅读