【问题标题】:Assert that viewController is both delegate and dataSource of its tableView断言 viewController 既是其 tableView 的委托又是数据源
【发布时间】:2016-09-30 17:10:52
【问题描述】:

作为健全性检查,我想在viewDidLoad 中断言UITableViewController(即self)设置为dataSourcedelegatetableView。我怎样才能把它放在需要额外类型转换的 Swift 3 中(与 Objective-C 不同)?这仍然会导致语法错误:

assert(tableView.dataSource == self)
assert(tableView.delegate   == self)

【问题讨论】:

    标签: swift uitableview uiviewcontroller swift3 assert


    【解决方案1】:

    您可以使用对象实例相等运算符'==='来做到这一点:

    assert(tableView.dataSource === self)
    assert(tableView.delegate === self)
    

    【讨论】:

    • 谢谢。菜鸟失误!
    猜你喜欢
    • 1970-01-01
    • 2018-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-03
    • 2016-01-17
    • 1970-01-01
    相关资源
    最近更新 更多