gpt4 book ai didi

swift - 我收到此错误 "Attempt to set a non-property-list object as an NSUserDefaults"

转载 作者:行者123 更新时间:2023-11-30 10:47:28 40 4
gpt4 key购买 nike

这是我收到的完整错误消息:

作为NSUserDefaults/CFPreferences键的值 Login_Data

2019-04-02 09:44:56.191207+0530 Level Up[238:4101] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object

这是我的代码:

let data = response.result.value as! NSDictionary

print(data)

if data["error-code"] != nil {
if data.object(forKey: "error-code")as! String == "\(200)"
{

let arrTimer = ((data.object(forKey: "data") as! NSDictionary).object(forKey: "timers") as! NSArray).mutableCopy() as! NSMutableArray

UserDefaults.standard.set(arrTimer , forKey: "ArrayTimer")
UserDefaults.standard.set((data.object(forKey: "data") as! NSDictionary), forKey: "Login_Data")

我在从后端更改用户电子邮件时收到此消息。对于新用户来说效果很好。我希望这些代码足以让您了解我正在尝试做什么。

最佳答案

看起来问题是字典有 NSNull 或 nil 值,并且尝试将其存储在 UserDefaults 中不起作用。该库可能应该使用 NSKeyedArchiver 来解决这个问题。将字典转换为数据,然后将其保存在 UserDefaults 中。

关于swift - 我收到此错误 "Attempt to set a non-property-list object as an NSUserDefaults",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55467020/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com