Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if UITableViewDelegate is equal to self

Tags:

swift

How could I get this to compile?

assert(self.tableView.delegate == self)

where self is a UIViewController containing the tableview

I get

WjateverViewController.swift:56:44: Binary operator '==' cannot be applied to operands of type 'UITableViewDelegate?' and 'WjateverViewController'

you'd think that maybe

assert(myTableView.delegate == self as UITableViewDelegate?)

would work. But it does not:

OffersViewController.swift:56:44: Binary operator '==' cannot be applied to two 'UITableViewDelegate?' operands

I could use help with this wonderful new language.

like image 228
Anton Tropashko Avatar asked Jul 17 '17 12:07

Anton Tropashko


1 Answers

The table view controller and the table view delegate are instances of a reference type (class).

Instances of reference types can be compared with the "identical-to" operator ===, which returns true if both references point to the same object instance:

assert(self.tableView.delegate === self)
like image 141
Martin R Avatar answered Sep 28 '22 04:09

Martin R