无法将Swift字典写入Beta 5中的NSUserDefaults [英] Unable to Write Swift Dictionary to NSUserDefaults in Beta 5

查看:132
本文介绍了无法将Swift字典写入Beta 5中的NSUserDefaults的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用一个应用程序,其中我的用户NSUserDefaults持续一个字典在程序的其他地方使用。自Beta 1以来,这一切都很完美。现在随着最新的更新(beta 5),这不再适用。看来他们已经删除了以这种方式坚持一个快速字典的能力。但是,我可以坚持一个NSDictionary。这是一个代码片段,工作2天前,现在已损坏。

I have been working on an app in which I user NSUserDefaults to persist a Dictionary for use elsewhere in the program. This been working perfectly since Beta 1. Now with the latest update (beta 5) this no longer works. It appears they have removed the ability to persist a swift Dictionary in this manner. However, I can persist an NSDictionary. Here is a code snippet that worked 2 days ago and now is broken.

var userDefaults = NSUserDefaults.standardUserDefaults()
userDefaults.setObject(allPlayersDict, forKey: "playerDict")
userDefaults.synchronize()

此代码不会对NSUserDefaults写入任何东西,甚至不会在使用以下选项时使用该键:

This code does not write anything to the NSUserDefaults, not even the key, when checked using:

var testDict = NSUserDefaults.standardUserDefaults().dictionaryRepresentation()
println(testDict)

有没有人经历过这个或有一个解决方案?

Has anyone else experienced this or have a solution?

推荐答案

自从Beta 5以来,我经历了完全相同的问题。有趣的是,当将代码部署到真实的代码时,代码工作正常iPhone 5s脱机,但在模拟器中似乎不起作用。

I have experienced the exact same issue since beta 5. Interestingly the code works fine when deploying it to a real iPhone 5s divice but It does not seem to work in the simulator.

关注

这篇关于无法将Swift字典写入Beta 5中的NSUserDefaults的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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