将NSMutableDictionary的内容复制到另一个NSMutableDictionary中? [英] Copying the contents of an NSMutableDictionary into another NSMutableDictionary?

查看:424
本文介绍了将NSMutableDictionary的内容复制到另一个NSMutableDictionary中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSMutableDictionary 其中每个元素都是另一个字典。我可以将其内容复制到另一个 NSMutableDictionary 的最佳方法是什么?我尝试过使用:

I have an NSMutableDictionary each element of which is another dictionary. What is the best way I can copy its contents into another NSMutableDictionary? I've tried using:

firstDictionary = [NSMutableDictionary dictionaryWithDictionary:secondDictionary];

但不确定这是否是最佳方式。

However not sure if this is the best way to do it.

推荐答案

检查NSDictionary initWithDictionary:copyItems:方法。

Check the NSDictionary initWithDictionary:copyItems: method.

它可以通过调用copyWithZone:item类的方法来深度复制元素。您必须自己在方法中自己复制字段。

It it enables deep copying of elements thru calling copyWithZone: method of item's class. You will have to take care of copying the fields yourself within the method.

这篇关于将NSMutableDictionary的内容复制到另一个NSMutableDictionary中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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