0

I am trying to figure out how to reset a label in an app after every 7 days even though the user launches the app on the 8th day.

To simplify the approach I have a label with a string set to it in ViewDidLoad.

override func viewDidLoad() {
    super.viewDidLoad()

    self.nameLabel.text = "Today"

    // Check for the current day
    let date = Date()
    let formatter  = DateFormatter()
    formatter.dateFormat = "EEEE"
    let WeekDay = formatter.string(from: date)
}

I can check for which day it is but is there a way to ensure I save the day and then check if the day has passed Sunday to then change the label to something else?

Thanks in advance.

Leo Dabus
  • 216,610
  • 56
  • 458
  • 536
Gugulethu
  • 1,366
  • 3
  • 16
  • 36
  • 1
    Just save the date to UserDefaults and next time your app starts just get the date components `[.day]` from the saved date to today's date and check if it is greater than 7 if not save it again to UserDefaults – Leo Dabus Sep 21 '16 at 19:38
  • I see. Do you mind posting the code. Apologies I am little new to user defaults and how they work. – Gugulethu Sep 21 '16 at 19:44
  • Sorry man, I don't mind posting the code but SO it is not a code writing service, I gave you all you need to accomplish that. First you need to try it your self and post another question with your attempt and whats not working. I can help you in every step but I won't lift you straight there. – Leo Dabus Sep 21 '16 at 19:52
  • http://stackoverflow.com/a/34846677/2303865 You can use as reference saving the date to user defaults – Leo Dabus Sep 21 '16 at 19:56
  • http://stackoverflow.com/a/27184261/2303865 to get the difference in days – Leo Dabus Sep 21 '16 at 19:57
  • 1
    Alright will give it a shot and get back to you. Thanks. – Gugulethu Sep 21 '16 at 20:03
  • you are welcome – Leo Dabus Sep 21 '16 at 20:07

0 Answers0