我想记录她输入文本框的历史记录,打算使用UserDefaults进行注册。但是当我试图使用UserDefaults保存时,“cannot assign value of type 'nsdate'?'to type 'String' ” 错误出现了。我认为它不接受文本框数据,因为它是字符串。那么如何在内存中保留历史记录?
formatteddate和formatteddate2出现错误。日期输出如下:20/04/2019 20:23
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