0

I’m trying to create a habit tracker using CoreData and JTAppleCalendar.

I want the user to be able to create a habit and then when completed on a set date it saves it for the day. The interface would show a calendar which the user can set habits for certain dates.

Struggling to work out how to implement the model with the calendar to get this working.

How should I construct the model for CoreData?

Khoa Le
  • 95
  • 2
  • 7
Gerry
  • 1,159
  • 1
  • 14
  • 29

1 Answers1

0

Here is one way to implement this.

  1. Make a model for Habit with attributes like name of the habit, start date and end date.
  2. Create a model for ReminderObjects with attributes like fireDate, completedStatus etc.
  3. Now create a relationship from Habit to ReminderObjects as one-to-many.

When the user creates an object for Habit, create the corresponding ReminderObjects, for that Habit, for all the dates between startDate and endDate as the fireDate of the ReminderObjects.

Now when displaying in the JTAppleCalendarView

  1. Filter the ReminderObjects for the Habit you want to display
  2. Filter the ReminderObjects from the fireDate when the user selects a date from the JTAppleCalendarView.
Kapil Rathore
  • 82
  • 1
  • 10
  • Could you explain what the attribute fireDate would be used for in your example? Also, I wanted to have the option for a user to have no end date, only have which days of the week they want the habit to re-ocurr (e.g. Repeat every Sunday), how could I implement this kind of function? – Gerry Aug 03 '18 at 01:34
  • fireDate is the date and time when you want the user to get the notification. fireDate is dynamically calculated for each ReminderObject when the user creates a habit object based on the days he selects. For the second part. you can create the ReminderObjects for one week at a time. (eg - Sat-Sun both @ 7:00AM) and then create new ReminderObjects for the next week when previous notifications are fired. – Kapil Rathore Aug 03 '18 at 06:31
  • If you want I could write a blog post if you could send me the exact problem statement over email. Hope that helps. – Kapil Rathore Aug 03 '18 at 06:32