用户默认值尝试设置非属性列表对象
Posted
技术标签:
【中文标题】用户默认值尝试设置非属性列表对象【英文标题】:User Defaults Attempt to set a non-property-list object 【发布时间】:2019-10-12 11:47:34 【问题描述】:我在将具有 39 个参数(键和值)的 NSDictionary 对象存储到 UserDefault 对象时遇到了问题。代码在我留下评论的地方崩溃。 self.userDefaults.set(data, forKey: "userData")
这是我得到的错误:
[User Defaults] Attempt to set a non-property-list object
city = "";
country = "";
cover = "default.png";
date = "2019-10-02";
description = "";
email = "hashdoge@outlook.com";
"email_comment" = 0;
"email_like" = 0;
"email_new_friend" = 0;
"email_newsletter" = 1;
facebook = "";
"first_name" = "";
follower = 3;
following = 2;
gender = 0;
gplus = "";
idu = 42;
image = "default.png";
ip = "";
"last_name" = "";
lastfm = "";
likes = 3;
"login_token" = "<null>";
"logout_time" = 0;
myspace = "";
notificationc = 1;
notificationd = 1;
notificationf = 1;
notificationl = 1;
offline = 0;
online = 1570879800;
password = "$2y$107675ze1wZ/riJgQ2e";
private = 0;
salted = "$2y$10$GKUmSJGcq932DMJGMA8791RIO";
soundcloud = "";
suspended = 0;
totaltracks = 0;
tumblr = "";
twitter = "";
username = HashDoge;
vimeo = "";
website = "";
youtube = ""; as an NSUserDefaults/CFPreferences value for key userData
这是我正在尝试制作的代码 代码:
func callApigetLoginResponse()
FTIndicator.showProgressWithmessage("", userInteractionEnable: false)
let parameters = ["useremail":txtEmail.text!,"password":txtPassword.text!]
SignInGet.ApiGetSignIn(parameters: parameters as NSDictionary) (Result, Error) in
// print(Result!)
if Error != nil
print(Error!)
else
let dataDict:NSDictionary = Result as! NSDictionary
if (dataDict["success"]as! Int == 1)
let loginResponse = dataDict["userlogin"] as! NSArray
let data = loginResponse[0] as! NSDictionary
let uid = data["idu"] as! String
self.sendTokenaApi(uid: uid)
self.userDefaults.set(uid, forKey: "id")
self.userDefaults.set(data, forKey: "userData") // code crashes here
self.userDefaults.synchronize()
let updateUserInfo = UpdateUserInfoUtl()
updateUserInfo.callApigetUserDataResponse()
self.pushToHomeController()
else if (dataDict["success"]as! Int == 0)
let message = dataDict["userlogin"] as! String
FTIndicator.showInfo(withMessage: message)
【问题讨论】:
请显示 Hashdoge 的代码 - 如果您的代码应该工作,这必须是可编码的 HashDoge 我想应该是一个字符串。感谢您指出它看起来像一个对象。 这里是完整代码shrib.com/?v=md#FTRdSlSdCZn6z8w7VB38 很遗憾仍然没有 hashdoge 的定义 它不存在于整个代码中。这是输入的用户名。 【参考方案1】:我修好了。问题是 login_token 中的“”。 我在数据库中将其设置为空字符串“”,并且可以正常工作。
【讨论】:
以上是关于用户默认值尝试设置非属性列表对象的主要内容,如果未能解决你的问题,请参考以下文章