UserDefaults.standard set nil XCode 8和Swift 3中的错误 [英] UserDefaults.standard set nil Error in XCode 8 and Swift 3

查看:62
本文介绍了UserDefaults.standard set nil XCode 8和Swift 3中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个错误.我正在尝试删除默认值中的现有值.

This seems a bug. I am trying to remove an existing value in the defaults.

UserDefaults.standard.set(nil, forKey: "test-me")
let val = UserDefaults.standard.object(forKey: "test-me")
print ("val=\(val)")

我得到以下输出-

<代码> VAL =可选(小于62706c69 73743030 d4010203 04050608 09582476 65727369 6f6e5824 6f626a65 63747359 24617263 68697665 72542474 6f701200 0186a0a1 0755246e 756c6c5f 100f4e53 4b657965 64417263 68697665 72d10a0b 54726f6f 74800008 111a232d 3237393f 51545900 00000000 00010100 00000000 00000c00 00000000 00000000 00000000 00005b>)

我正在XCode 8/iOS 10/iPhone 7模拟器中运行.

I am running in XCode 8 / iOS 10 / iPhone 7 simulator.

推荐答案

Rob在另一篇文章中的评论似乎正确.将该值设置为"nil"会将其另存为NSData.要删除密钥,请尝试以下操作:

The comment from Rob in the other post looks correct. Setting the value to "nil" will save it as NSData. To remove the key, try this instead:

UserDefaults.standard.removeObject(forKey: "test-date")

在执行 object(forKey:"test-date")

这篇关于UserDefaults.standard set nil XCode 8和Swift 3中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆