如何将 NSMutableDictionary 值复制到 iPhone 中的另一个 NSMutableDictionary 中?
我想将 NSMUtableDictionary 值复制到另一个 NSMutableDictioary 中。我怎样才能做到这一点?
我的代码是,
PersonClass.h file:
NSMutableDictionary *tempDictionary;
@property (nonatomic, retain) NSMutableDictionary *tempDictionary;
PersonClass.m
@synthesize tempDictionary;
tempDictionary = [[NSMutableDictionary alloc] init];
-(PersonClass *) initWithPerson:(NSMutableDictionary *) feedDictionary
{
// get all the values in feedDictionary.
//Now i want copy of the details from feedDictionary into the tempDictionary
tempDictionary = feedDictionary; // Doesn't copy.
}
我想访问 person 类的 tempDictionary 值。那么我如何从 feedDictionary 复制到 tempDictionary。请帮帮我。
谢谢。
I want to copy a NSMUtableDictionary values into the another NSMutableDictioary. How can i do that?
Here my code is,
PersonClass.h file:
NSMutableDictionary *tempDictionary;
@property (nonatomic, retain) NSMutableDictionary *tempDictionary;
PersonClass.m
@synthesize tempDictionary;
tempDictionary = [[NSMutableDictionary alloc] init];
-(PersonClass *) initWithPerson:(NSMutableDictionary *) feedDictionary
{
// get all the values in feedDictionary.
//Now i want copy of the details from feedDictionary into the tempDictionary
tempDictionary = feedDictionary; // Doesn't copy.
}
I want to access the tempDictionary values to the person class. SO how can i copy from feedDictionary to the tempDictionary. Please help me out.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这个怎么样?
干杯
How about this?
Cheers
这将复制字典中的所有条目,但不会复制自定义对象,除非您实现 NSCopying 协议。
This will copy all entries in the dictionary, but it will not copy custom objects unless you implement the NSCopying protocol.
获取字典的深层可变副本的一个非常简单的方法是使用 JSON。
它还提供了查看字典中的值的机会
a very simple way to get a deep mutable copy of a dictionary is to use JSON.
It also gives the chance to have a look at values in dictionaries
这是另一种保存方法。
假设您已将名为“dictA”的可变字典复制到名为“dictB”的新可变字典中。但要确保 dictB 有 alloc 和 init。
希望这有帮助。
Here is another way to save.
Suppose you have copy mutable dictionary named "dictA" into new mutable dictionary named "dictB". but make sure dictB have alloc and init.
Hope this helpful.