title: How to keep track of data over various periods of time (Swift) - Counter/Habit Tracking App
body: <p>I'm trying to create a simple counter/habit tracking app that allows users to see how many times they've completed a task over a certain amount of time (daily/weekly/monthly/yearly/total). </p>
  
  <p><strong>My question is: what is the best way to track variables over time such that when the user selects a time period, the variable's value can update to reflect that change?</strong> </p>
  
  <p>A few examples to clarify what I mean:</p>
  
  <ul>
  <li>A user who initially created a monthly timer to track workouts should be able to switch to a weekly timer and see the data update as needed (there should be fewer in a week than in a month).</li>
  <li>A user who has created a daily counter should see the daily counter reset to 0 at midnight each day, with the previous day's value visible to compare.</li>
  <li>A user who has created a "total" counter should be able to switch to any time period (daily/weekly/monthly/yearly) and see the counter update as needed.</li>
  </ul>
  
  <p>The UI for my app is basically a custom tableview with the counter number, counter name, and the time period over which the counter number is being tracked. A detail view allows users to add to/subtract from the counter's value.</p>
  
  <p>I have been wracking my brain and Google for a long time, so I'd really appreciate any help!</p>