Getting an error of Thread 1 bounds fail

Yes, the array drives the tableView and the two methods numberOfRowsInSection and cellForRowAt work hand in hand.

In order for the cellForRowAt method to know how many rows it has to deal with, the numberOfRowsInSection method returns a count of the number of elements in the array.

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return allFruit.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Fruit")

        let fruit = allFruit[indexPath.row]
        cell?.textLabel!.text = fruit
        cell?.textLabel?.font = UIFont.systemFont(ofSize: 20) // Better option here than previously

        return cell!
    }

The other thing you perhaps ought to think about is how you plan to show more details about a specific item of fruit. Ideally you should have some structure that defines the properties of an item of fruit such as:

  • name
  • size
  • color
  • taste
  • growingConditions
  • image

This would be the source of data for your detail view where each of those properties would be displayed.

Does that make sense?