0

I'm making a SwiftUI Budget app where user can add a transaction (CoreData entity) and make it recurring by choosing start date and recurrence interval: weekly, every two weeks, monthly, every 3/6 month or yearly. I'm using Picker for both date and interval.

I'm new to app development so at this stage I'm stuck with no solution as to how to implement recurrence. For example I've read about Timer class, but couldn't figure out how to pass recurrence interval ( every month, 3 month etc) to Timer interval to match user current Calendar.

Could someone please help me out with sort of general structure/ idea of what needs to be done/used to implement this?

  • Look into event kit – lorem ipsum Jan 20 '22 at 18:13
  • @loremipsum Thanks, but event kit is for adding events to Calendar. I apologise if my question is not very clear, but what I'm trying to achieve is to run _addNewTransaction_ function at a certain interval. – Kuskoveckis Jan 20 '22 at 18:32
  • There is no guarantee your app will be running when your event happens. What you need is to calculate the date events and every time the user opens the app check which events have already happened and which one still waiting to happen. For long periods what you need is to schedule the next fireDate when the last happened. – Leo Dabus Jan 20 '22 at 18:57
  • This might help https://stackoverflow.com/a/62665165/2303865 – Leo Dabus Jan 20 '22 at 19:04
  • That would likely have to be something that is done by a server online. If the user terminates the app nothing is guaranteed. You can look into background tasks and try to schedule them but they might not run either. Timer stops for sure even when you app is just i the background. – lorem ipsum Jan 20 '22 at 19:42
  • @loremipsum Check the second link of the duplicated post. `UNUserNotificationCenter` normally only works if your app is NOT in foreground. – Leo Dabus Jan 20 '22 at 20:13
  • @LeoDabus I didn’t suggest notifications. Also they do work if the delegate is told what to do with the notification when the app is in the foreground. The delegate has a method for that. I was talking about event kit which is different. But it seems the user wants to perform tasks at intervals not just get notified. – lorem ipsum Jan 20 '22 at 21:18
  • @loremipsum that's why I said "normally". Anyway there is no way to "execute" those tasks while the app is in the background. – Leo Dabus Jan 20 '22 at 21:29

0 Answers0