title: How to store date in userdefaults?
body: <p>I'd like to record the history of her entry into the textfield. I intend to register this with UserDefaults. But when I try to save it with UserDefaults, "cannot assign value of type 'nsdate'?'to type 'String' " Error. I don't think it's accepting textfield data because it's string. And how can I keep history in memory? </p>
  
  <p>formatteddate and formatteddate2 give this error. The date output is as follows : 20/04/2019 20:23</p>
  
  <pre><code>let token = try? keychain.getString("chipnumbernew")
          chip1InfoString = token
  
          var time = NSDate()
          var formatter = DateFormatter()
          formatter.dateFormat = "dd/MM/yyyy HH:mm"
          var formatteddate = formatter.string(from: time as Date)
          var formatteddate2 = formatter.string(from: time as Date)
  
          timertextNew.text = formatteddate
          timertext2New.text = formatteddate2
  
  
          let RetrivedDate = UserDefaults.standard.object(forKey: "timertext") as? NSDate
  
         formatteddate = RetrivedDate
  
          let RetrivedDate2 = UserDefaults.standard.object(forKey: "timertext2") as? NSDate
          formatteddate2 = RetrivedDate2
  </code></pre>