I'm trying to call viewModel.userDidSelectItem(identifier: "DetailMainViewController") function when the user clicks on a cell but I'm not able, first print(indexPath.row) is nil and second I don't know if its correct the call.
import Foundation import UIKit class MainViewController: UIViewController, UITableViewDataSource { @IBOutlet var tableview:UITableView! var viewModel: MainViewModel = MainViewModel() override func viewDidLoad() { super.viewDidLoad() viewModel.loadUsers { self.tableview?.reloadData() } } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return viewModel.fakeUsers?.count ?? 0 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "fakeUserObjectCell") as! MainTableViewCell cell.fakeUserObject = viewModel.fakeUsers?[(indexPath as NSIndexPath).row] return cell } func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { print(indexPath.row) viewModel.userDidSelectItem(identifier: "DetailMainViewController") } }