I have a dictionary with the same keys:
var food = [["item" : "Burger", "image": "burger"],
["item" : "Pizza", "image": "pizza"],
["item" : "Lunch", "image": "lunch"],
["item" : "Coffee", "image": "coffee"]],
And it is used in my table view. Each cell dispalys a name.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Cell
let foodObjects = food[indexPath.row]
cell.background.image = UIImage(named: foodObjects["image"]!)
cell.nameLabel.text = foodObjects["item"]
return cell
}
And what I want, is item value from selected cell be passed to second View Controller. I know that I can do this throughout this function, but I cannot get a value from selected item. Could somebody help me?
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let indexPath = self.tableView.indexPathForSelectedRow?.row
let resVC = segue.destination as! RestaurantVC //second View controller
let selectedItem = food[indexPath.["item"]] // How to do this??
}