I'm adding a UIAlertAction with the following code:
@IBAction func doneButtonTapped(_ sender: Any) {
self.present(lastInstructionAlert, animated: true, completion: nil)
lastInstructionAlert.addAction(UIAlertAction(title: "Back", style: .default, handler: { (action) in
print("Go Back")
return
}))
lastInstructionAlert.addAction(UIAlertAction(title: "Home", style: .default, handler: { (action) in
print("Go Home")
self.present(self.mealPlanViewController, animated: true, completion: nil)
}))
}
The issue is that when the user presses "Back" and then "Done" again, it adds the UIAlertActions again resulting in duplicates.
How can I prevent those UIAlertActions from being added again if they were already added before?

As you make
lastInstructionAlertan instance variable every time you click the actiondoneButtonTappednew alert actions are added , so make it localOr move adding the alert actions say to
viewDidLoad