无法将Swift字典写入Beta 5中的NSUserDefaults

编程入门 行业动态 更新时间:2024-10-17 13:29:29
本文介绍了无法将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

本文发布于:2023-11-26 13:34:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634032.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字典   Swift   NSUserDefaults   Beta

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!