Keeping track of which buttons have been favorited

I want to create an app with a view of several buttons, each labeled with the name of a certain candy. When a button is pressed, I want to change the appearance of the button to indicate it has been favorited, and also for the button to then appear on a separate view, with all the other candy buttons that have been favorited. When tapped again, the button should “unfavorite”.

I am not sure how to keep track of which candy types have been favorited in order to do this.

Thanks!

In whatever data structure you have to represent each type of candy, add a var isFavorite: Bool property that you can toggle when the candy’s button is pushed. You would check the state of isFavorite when you display the button and adjust its appearance according to whether the property is true or false