小编sta*_*kor的帖子

如何在用户默认值中存储日期?

我想记录她进入文本字段的历史。我打算用 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)

date swift

19
推荐指数
2
解决办法
1万
查看次数

java.io.IOException: No such file or directory (save image)

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)

android android-10.0

4
推荐指数
2
解决办法
4255
查看次数

标签 统计

android ×1

android-10.0 ×1

date ×1

swift ×1