Drux
Drux

Reputation: 12670

Assert that viewController is both delegate and dataSource of its tableView

As a sanity check, I would like to assert in viewDidLoad that a UITableViewController (i.e. self) is set both as dataSource and delegate of its tableView. How can I put this in Swift 3, where (unlike with Objective-C) additional type casts are needed? This still leads to syntax errors:

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

Upvotes: 1

Views: 46

Answers (1)

warby
warby

Reputation: 160

You can do this using the object instance equality operator '===':

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

Upvotes: 1

Related Questions