Andrew Wang
Andrew Wang

Reputation: 65

How do I reset a variable at 12pm every night? swift

I am trying to develop a tracking app that tracks if you do a certain thing every day. Users will be able to press a button to say they did that thing that day. The challenge I am facing is how do I reset a variable that says they've completed that item every night at 12pm. What would be the best approach to this?

Upvotes: 0

Views: 176

Answers (1)

Mick F
Mick F

Reputation: 7439

I don't think your approach (ie reset a variable) is right here as, if you intend to run on an iOS device, you can't be certain your app is going to keep alive forever: cf. Execution States for Apps in The App Life Cycle.

What you can do though is:

  • listen for taps on the button,
  • persist the information with the associated timestamp,
  • process all the taps you tracked to apply your logic, ie show the daily completion to your user in the UI, etc.

Hope it helps.

Upvotes: 1

Related Questions