我一直在使用一个应用程序,其中我的用户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
发布评论