I'm making a FlashCards app and I would like to set a timer for the cards in a way so that if the user knows the answer, the card will trigger again next day, then if he knows it again, it will trigger in 5 days and so on. I haven't found anything related to this, any help with it?
2 Answers
In case when users don't quit app you can use Timer. However, this is only expected for short intervals.
let minute = 60
let anotherTimeInterval = 2 * minute
var timer = Timer.scheduledTimer(timeInterval: minute, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: false)
@objc func updateTimer() {
// do something
timer.invalidate()
timer = Timer.scheduledTimer(timeInterval: anotherTimeInterval, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: false)
}
Normally, you need to prepare a specific data source for a specific day. For example, in your case, you can add a flag or date to each card and use that flag or date to add that card to the data source on a specific date.

- 55
- 1
- 5
-
i'm sorry but i think this function is not useful. We do not use an app for more than 5 days in a row. The Timer will be stopped every time the User quits the app. – mjoe7 Mar 08 '21 at 10:59
-
Ok. In this case you need to prepare a specific data source for a specific day. For example, in your case, you can add a flag or date to each card and use that flag or date to add that card to the data source on a specific date. I have updated my answer. – Carrione Mar 08 '21 at 12:24
Get track of the Dates and the User's performance with each card. (You can use a Timer here. For instance, if the User 'knows' the answer within a minute, the card will be marked as 'correct' (known), and beyond that time, the card will be marked as 'wrong' (not yet mastered and needs to be repeated).
Create a logic wherein the cards marked as 'wrong' will popup after a few days or so.
I suggest you use CoreData to save the Dates
when the User uses the Flashcard app.
Also, you will need to learn how to use DateComponents()
.
Here's a great resource.

- 134
- 6
-
I came up with a solution that should work using the CoreData for dates and the DateComponents() to establish future dates. Thanks a lot! – Pablo Coranta Mar 08 '21 at 11:34