如何将NSMutableDictionary保存到文档中的文件中? [英] How to save a NSMutableDictionary into a file in documents?

查看:93
本文介绍了如何将NSMutableDictionary保存到文档中的文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将NSMutableDictionary对象的内容保存到文件中。我该怎么做呢 ?我已经知道如何使用NSDictionary对象执行此任务但我不知道如何将此NSMutableDictionary转换/复制到NSDictionary ...除非有一种方法直接将NSMutableDictionary的内容写入文件...我强调NSMutableDictionary对象包含NSDictionary类型的对象。

I would like to save the content of a NSMutableDictionary object to a file. How do I do this ? I already know how to do this task with a NSDictionary object but I don't know how to convert/copy this NSMutableDictionary to a NSDictionary...unless there's a method to write directly the content of NSMutableDictionary to a file...I stress that the NSMutableDictionary object contains objects of NSDictionary type.

Thx用于帮助,

Stephane

推荐答案

NSMutableDictionary NSDictionary的子类:您可以在任何使用 NSDictionary 的地方使用它。从字面上看,只需将对象传递给您现在用于 NSDictionary 的相同代码。

NSMutableDictionary is a subclass of NSDictionary: you can use it anywhere you'd use NSDictionary. Literally, just pass the object through to the same code you use for NSDictionary right now.

更一般感觉,如果您真的需要从 NSMutableDictionary 获得真正不可变的 NSDictionary ,只需调用复制 NSMutableDictionary

In a more general sense, if you ever actually need to get a truly immutable NSDictionary from an NSMutableDictionary, just call copy on the NSMutableDictionary.

其他方法包括 [NSDictionary dictionaryWithDictionary:] [NSDictionary alloc] initWithDictionary:] ,这些都基本相同。

Other approaches include [NSDictionary dictionaryWithDictionary:] or [NSDictionary alloc] initWithDictionary:], which all amount to essentially the same thing.

这篇关于如何将NSMutableDictionary保存到文档中的文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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