'How to maintain a View that depends on a time-based CoreData query up to date in SwiftUI?

I have a view that shows flashcards to the user. The user reviews the cards and when there are none left to be reviewed, the view shows a success screen.

Each card is stored in CoreData and has a due_for_next_review_date field which gets updated on each review. Currently when the user finished reviewing their cards, they get their success screen, but there is no mechanism to let the view know that some time has passed, and a card's due_for_next_review_date field has gone below the current time, and that it should therefore now be shown to the user. They have to exit and re-enter this view to refresh the cards for review, which is not ideal.

Basically what I want is a way for my view to poll CoreData and check if any cards have had their due_for_next_review_date field go below the current date, and should be shown. Is there a way to do this? I've tried TimelineView, which lets me re render the view, but the view doesn't re execute the CloudKit query regrettably.

Anyone know how to do this?

Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source