I have two View Controllers A & B.
In ViewController B, I have a button that adds an item to an array with a click
var list = [Items]()
@IBAction func addButton(_ sender: UIButton) {
let indexPath = IndexPath(row: sender.tag, section: tagPassedOver)
list.append(Items(category: "Toys", name: toys[indexPath.row], price: toysPrice[indexPath.row]))
}
ViewController A
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if self.isMovingFromParent {
// how do i send the data back in here??
}
}
Problem: When I click the back button in the navigation bar of View Controller B to go to View Controller A, my "list" array has been reset. So, my previous elements are no longer stored in the array, and if I click the button in View Controller B it creates a brand new array. I found something to help here but I do not know what insert in the if statement. Or is there a way to do this with segues? I just need to know how to send data backwards (Lmk if you need more clarification, I had to simplify my code to get an answer for this specific issue)
Goal: be able to go back/forth between views and preserve the contents of my array