Learn Courses My Dashboard

Is there a way of reloading a View Controller upon completion of a function?

I am using the following syntax in a View Controller (using a Storyboard) to remove the second element of an array in a database.

@IBAction func deleteItemOne(_ sender: UIButton) {
if userId == user?.uid {
  let group_array = document["product"] as? [String] ?? [""]
    if  (group_array.count) > 1 {
          "product": FieldValue.arrayRemove([group_array[1]])

Once the element of the array has been removed, I am using the following syntax to then reload the View Controller.


However after removal of the element, the View Controller doesn’t reload as intended, and in-fact it doesn’t end up doing anything.

This leads to my question, is there a simple Swift function / method that I can call to reload the View Controller upon completion? If not, how would I go about creating my own function to do this?

Are you attempting to reload like a TableView that’s on the VC?

Typically you don’t call those methods manually

What’s your view controller look like?

My View Controller has a few UITextLabels on which are populated with data, however once I delete one of these, I want the View Controller to then refresh to reflect the new IDs if that makes sense? Here’s a screenshot of my View Controller currently.

Here’s my View Controller with two items on:


Once I proceed to delete Item 1 it deletes the item from the array, but it isn’t reflected on the VC straight away, hence the need to refresh it (as shown below the Item 2 is shown twice)

Is this not in a table view??

I think it should be, and this would be a lot easier