title: Formatting UITableViewCell date in ViewModel
body: <p>I'm setting a TableView and would like to know what is the proper way to set UITableViewCells with viewModel.</p>
  
  <p>Let's say I've got a model: </p>
  
  <pre><code>class Item {
     var date: Date!
     var info: String?
  }
  </code></pre>
  
  <p>and my viewModel for the main ViewController has a property which is an array of Item objects. </p>
  
  <ol>
  <li>I've declared the protocol for cell's view model. Should it contain properties like <code>var date: String</code> and <code>var info: String</code> (with Item initializer, so basically formatted data that are going to be displayed inside the cell) or I should keep the Item object here?</li>
  <li>Who is responsible for formatting the date inside the cell? I assume cell's view model is responsible for that but on the other hand is it efficient to have dateFormatter instance inside every ViewModel? Maybe it's better to pass the dateformatter from the other class and hold only one reference?</li>
  </ol>
  
  <p>My main viewController (methods related to the tableView)</p>
  
  <pre><code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
          let cell = tableView.dequeueReusableCell(withIdentifier: "itemCell", for: indexPath) as? ItemTableViewCell
  
          cell?.viewModel = viewModelForCell(at: indexPath.row)
          cell?.setupCell()
          return cell ?? UITableViewCell()
      }
  
      private func viewModelForCell(at index: Int) -&gt; ItemTableViewCellRepresentable {
  
          let item = viewModel?.items[index]
          if let item = item {
              return ItemTableViewModel(item: item, formatter: viewModel.cellDateFormatter)
          }
          return ItemTableViewModel()
      }
  </code></pre>
  
  <p>cell's viewModel protocol:</p>
  
  <pre><code>protocol ItemTableViewCellRepresentable {
      var date: String { get }
      var info: String? { get }
  
      init(item: Item, formatter: DateFormatter)
  }
  </code></pre>
  
  <p>cell's viewModel class:</p>
  
  <pre><code>class ItemTableViewModel: ItemTableViewCellRepresentable {
  
      var date: String
      var info: String?
  
      required init(item: Item, formatter: DateFormatter) {
          self.date = formatter.string(from: item.date)
          self.info = item.info
      }
  
      init() {
          self.date = ""
          self.info = ""
      }
  
  }
  </code></pre>
  
  <p>and my cell:</p>
  
  <pre><code>(...)
  
  var viewModel: ItemTableViewCellRepresentable?
  
      func setupCell() {
          guard let viewModel = viewModel else {
              return
          }
  
          dateLabel.text = viewModel.date
          descriptionLabel.text = viewModel.info ?? "no info"
      }
  </code></pre>