title: How to check the amount of time between two NSDates?
body: <p>I'm making a kind of challenge based app that requires that the user comes back every day. If he misses one day, he has to start all over again.
  My problem is my dateChanged()-function; the first thing is, that it doesn't work very reliable, the second is that I just check if the date changed, I accordingly don't know if there were one or two days between using the app.
  Here's my current function:</p>
  
  <pre><code>public func changeDays()
  {
      myFormatter.dateStyle = .short
      myFormatter.locale = Locale(identifier: "de_DE")
  
      oldDate = defaults.string(forKey: "oldDate")!
      let newDate = Date()
      let newDateString = myFormatter.string(from: newDate)
  
      if newDateString == oldDate
      {
          NumberOfDaysInARow.text = "\(days) / 30"
      }
      else if newDateString != oldDate
      {
          days += 1
          NumberOfDaysInARow.text = "\(days) / 30"
          defaults.set(days, forKey: "days")
      }
  
      oldDate = newDateString
      defaults.set(oldDate, forKey: "oldDate")
  
  
  }
  </code></pre>
  
  <p>Just today it started giving me a fatal error when starting the app on my iPhone, did not happen in the simulator though... weird.
  How do I have to change my function to make it a 100% reliable (and working) while also being able to check the amount of time between the two dates?</p>
  
  <p>Thank you for having a look! Have a great day</p>