title: Swift UIKit Combine - How to reload tableview when handling publisher events?
body: <p>Using Combine and UIKit, I am trying to update my tableview when the array contained in the viewModel changes. My tableview's datasource is separate because I would like to reuse the file (Different objects all have a name var, so the tableviews will display a list of names).</p>
  <p>The viewModel:</p>
  <pre><code>class ViewModel {
    @Published var items = [ItemViewModel]()
    let service = NetworkService()
  
    init() {
      fetchItems()
    }
      
    func fetchItems() {
      service.fetchItems { items in {
      self.items = items.map { ItemViewModel($0) }
    }
  }
  </code></pre>
  <p>The datasource:</p>
  <pre><code>class GenericDataSource: UITableViewDataSource {
     var list = [String]()
  
     func setList(_ list: [String]) {
         self.list = list
     }
  
    // then the usual tableView datasource boilerplate
  }
  </code></pre>
  <p>The viewController:</p>
  <pre><code>class ViewController: UIViewController {
    let viewModel = ViewModel()
    let tableDataSouce = GenericDataSource()
    var subscriptions = Set&lt;AnyCancellable&gt;()
  
    func setupBinding() {
      // I want to: 1) map over viewModel.$items to get [item.name]
      //            2) assign the list of names to tableDataSource.list
      //            3) reload the tableview so the new values are displayed
    }
  </code></pre>
  <p>I'm not sure what Combine functions to use. My current (working) code is as follows:</p>
  <pre><code>func setupBinding() {
       viewModel.$items.handleEvents(receiveOutput: { [weak self] items in
           self?.dataSource.setList(items.map { $0.name })
           
              // dispatch called because I get yelled at for not being on main thread
              DispatchQueue.main.async { 
                   self?.itemsTableView.reloadData()
              }
          })
             .sink { _ in }
             .store(in: &amp;subscriptions)
   }
  </code></pre>
  <p>It works, but I feel like I'm brute forcing it. Is there a cleaner way to perform the binding with the current setup?</p>
  <p>Is there a cleaner way to setup the code so the binding will be easier?</p>