extensionRefreshablewhereSelf: UIViewController { /// Install the refresh control on the table view funcinstallRefreshControl() { let refreshControl = UIRefreshControl() refreshControl.tintColor = .primaryColor refreshControl.addTarget(self, action: #selector(handleRefresh(_:)), for: .valueChanged) self.refreshControl = refreshControl if #available(iOS 10.0, *) { tableView.refreshControl = refreshControl } else { tableView.backgroundView = refreshControl } } }
Protocol extension is cool but somehow I’m not a fan of it. I always consider composition first, to extract the specific task to one entity that does that well. It looks like this