Storing check status of toDo list

64 views Asked by At

I am developing a new screen in my app and I wanted to consult with you the best way to do it. The new screen is going to be a static checklist and I want the user to check "step-by-step" (i.e. line-by-line) that he completed the step.

I have 2 view controller VC1 = theme static list VC2 = step static list linked to each step --> you click on VC1.Theme1 and then it displays VC2.step1,2,3, etc.. in a static tableview.

What I want to do is: 1. checking steps in VC2 and "keep them in memory" 2. when all steps in VC2 are checked updated the status of the theme in VC1

If for 2. it is a simple calculation I am wondering what would be the best method to store the status of the step completion. I am hesitating between a database (custom) or the phone memory... I have not enough experience to know if there are other options or what is the best practice.

Any advise?

1

There are 1 answers

3
Tung Fam On BEST ANSWER

I believe the most simple way is to use UserDefaults.

I usually use it for simple data storage. For a start I think it's a good solution for you. For example you may store an array of Bools which indicates whether steps are checked or not. Or store a counter (int) that will indicate quantity of checked steps and compare it to total of steps in the VC2.

How to write to user defaults:

let defaults = UserDefaults.standard()
defaults.set(yourValue, forKey: "valueKey")

And read:

defaults.value(forKey: "valueKey")

Hope it helps.