I have a problem and do not know what to do.
My FirstViewController calls with
let secondVC = SecondViewController()
let navController = UINavigationController(rootViewController: secondVC)
navController.modalPresentationStyle = .automatic
self.present(navController, animated: true)
my SecondViewController.
In the SecondViewController, user can make various selections, such as selecting numbers.
The selected numbers are stored in a static variable of an enum located in the SecondViewController. (Why I do it this way is not important right now).
enum Numbers {
static var selectedNumbers: [Int] = []
}
If I return to my FirstViewController with dismiss the SecondViewController and then go back to my SecondViewController, I see that the enum from the SecondViewController still has the user's selection stored.
What exactly is the reason for this? And can I somehow prevent or solve this?
According to your expectation, I recommend changing the static to store property in
SecondViewController, and a callback to handle if needed, something like:In
FirstViewController, when you pop back fromSecondViewController, handle selected here:And if you still want to use static one, you can clear static property whenever
SecondViewControlleris dismissed: