'Implementied a counter, but it's not updating

So I am trying to limit a booking form to a few slots only this is my code after they have booked and when they press a button it will decrease the availability by 1

class SuccessfulViewController: UIViewController {
    var availability = 1
    
    @IBAction func countBtn(_ sender: Any) {
        availability -= 1
        performSegue(withIdentifier: "backtoavailability", sender: self)
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let availabilityViewController = segue.destination as! AvailabilityViewController
        availabilityViewController.countslots = String(availability)
    }

}

and here's the other view controller code to display the availability left

class AvailabilityViewController: UIViewController {
    
    @IBOutlet weak var availabilityLabel: UILabel!
    var atfirst = "1"
    var countslots = ""
    
    @IBAction func trybookbtn(_ sender: Any) {
        if availabilityLabel.text == "0" {
            performSegue(withIdentifier: "full", sender: self)
        }else {
            performSegue(withIdentifier: "booking", sender: self)
        }
    }

    override func viewDidLoad() {
    super.viewDidLoad()
        
        // Do any additional setup after loading the view.
    }
    override func viewDidAppear(_ animated: Bool) {
        if countslots == ""{
            availabilityLabel.text = atfirst
        } else {
            availabilityLabel.text = countslots
        }
        
    }
}

So now that the availability is 0, I will segue it to another view controller saying slots are full if the user tries to book and there is a home button as well. However, once I pressed the home button and checked the availability again, it is back to 1 and doesn't show 0 anymore. How can I let it stay at 0? Is it possible or do I have to implement a Firebase database?

I created the var at first as count slots would be empty b4 I booked a slot, is there a better way to do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source