How do I reset the properties in a class back to default in a singleton database

I want to be able to reset the properties of a class and then reload the table. I make changes in my app and then it saves the changes of the properties and when I return to the view, it loads the saved changes. I have a row in a table view that will reset the properties in the class back to the default properties. How do I implement this?

Accepted Reply

I make changes in my app and then it saves the changes of the properties and when I return to the view, it loads the saved changes.


Normal, if you save the changes to the database, when you reload, you get the changes.

What did you expect ?


If I understand well your question, what you could do is store 2 sets of data:

- original data

- current data (the one you saved)

Never change the original,

when resetting, reload original data.


This could be done in 2 ways:

- have 2 data sets in database

- for each property, store 2 values: original and current.

Replies

I make changes in my app and then it saves the changes of the properties and when I return to the view, it loads the saved changes.


Normal, if you save the changes to the database, when you reload, you get the changes.

What did you expect ?


If I understand well your question, what you could do is store 2 sets of data:

- original data

- current data (the one you saved)

Never change the original,

when resetting, reload original data.


This could be done in 2 ways:

- have 2 data sets in database

- for each property, store 2 values: original and current.

Thank you. It worked.


I created another variable in database


fileprivate var allPlayersReset: [PlayerData]


Then I initialized it by creating another data set.


Then I created a function and set allPlayers = allPlayersReset.


func resetDraft() {
    allPlayers = allPlayersReset
}


It works perfect.

Thanks for the feedback.


Wish you good continuation.