我想记录她进入文本字段的历史。我打算用 UserDefaults 注册它。但是,当我尝试使用 UserDefaults 保存它时,“无法将类型为 'nsdate'?' 的值分配给类型 '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
Run Code Online (Sandbox Code Playgroud) I upload the photos I selected from the device to ftp. But despite the photo I have chosen from the device, I get the "no such file directory" error. Although I give the application permissions, it does not save it to IMAGE_DIRECTORY that I have chosen in the application. So I get this error. What is the reason why it did not save the file, even though I gave the permissions?
Error line: f.createNewFile();
error code:
W/System.err: java.io.IOException: No such …Run Code Online (Sandbox Code Playgroud)