以 NSDates 作为键的 NSDictionary
是否有可能有一个 NSdictionary,其中键是 NSDates,并且可以将其写入/可存档到磁盘?
Is it possible to have an NSdictionary where the keys are NSDates and also have it writeable/archiveable to disk?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不使用属性列表,因为那里只允许使用字符串键。您应该能够使用 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.是的,这应该可以正常工作 - 并且 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.