How to set a timer for a string to trigger periodically?

118 Views Asked by At

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

There are 2 best solutions below

1
mjoe7 On BEST ANSWER

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.

2
Carrione On

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.