How to save a NSMutableDictionary into a file in documents?

后端 未结 2 1760
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-25 08:09

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 ho

2条回答
  •  清歌不尽
    2021-01-25 08:34

    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.

    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.

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

提交回复
热议问题