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 {
document.reference.updateData([
"product": FieldValue.arrayRemove([group_array[1]])
])
self.viewDidLoad()
self.viewWillAppear(true)
}
}
}
Once the element of the array has been removed, I am using the following syntax to then reload the View Controller.
self.viewDidLoad()
self.viewWillAppear(true)
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?