Checklist Question: How to create that tasks that repeat daily?

Hi,

I’m trying to build upon the checklist app tutorial, and wanted to create checklist items/tasks that repeat daily if the user wants it to repeat.

Not sure what’s the best way to approach this from a high level. Should the app create the repeating items ahead of time (several days at a time) and then only show the ones that are due that day? Or should the app only create new items,each time an user logs in and the app checks the date to see if it’s a new day? Would NSTimer help? Or do I need to do a lot of logic with NSDates?

Thanks for your help!

You shouldn’t have to create new items for tasks that repeat, just give them a var isRepeating: Bool property. However, you do need to create UNNotification objects for every repetition – I don’t think there is a way to schedule a repeating local notification (but I’m not 100% sure).

From the documentation, it seems like you could change this:

  let components = calendar.dateComponents([.month,.day,.hour,.minute], from: dueDate)
  let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: false)

to

  let components = calendar.dateComponents([hour,.minute], from: dueDate)
  let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)

and it will repeat the notification at the given hour and minute each day.

1 Like