以 NSDates 作为键的 NSDictionary

发布于 2024-10-05 20:56:15 字数 58 浏览 0 评论 0原文

是否有可能有一个 NSdictionary,其中键是 NSDates,并且可以将其写入/可存档到磁盘?

Is it possible to have an NSdictionary where the keys are NSDates and also have it writeable/archiveable to disk?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花心好男孩 2024-10-12 20:56:15

不使用属性列表,因为那里只允许使用字符串键。您应该能够使用 NSKeyedArchiver 来编写它,但这有一个缺点,那就是格式更加不透明。或者,您当然可以复制字典,将日期转换为字符串。

Not using property lists, as only string keys are allowed there. You should be able to write it using NSKeyedArchiver, but that has the disadvantage of being a more opaque format. Alternatively, you could of course make a copy of the dictionary where you convert the dates to strings.

合久必婚 2024-10-12 20:56:15

是的,这应该可以正常工作 - 并且 NSDate 元素也适合 plist 编码。不过,可能取决于您作为值输入的值。

如果您遇到问题,请使用代码更新您的问题。

Yes, this should work just fine - and NSDate elements are also suitable for plist encoding. Might depend on the value you put in as values, though.

If you experience problems, please update your question with code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文