如何将 NSDictionary 转换为 NSMutableDictionary?
我有一个现有的 NSDictionary,其中包含:
{
"charts_count" = 2;
"created_at" = "2010-04-12T16:37:32Z";
exchange = NASDAQ;
"followers_count" = 259;
id = 8404;
industry = "<null>";
"messages_count" = 1436;
ric = "GRPN.O";
sector = "<null>";
symbol = GRPN;
title = Groupon;
"updated_at" = "2011-09-05T04:17:56Z";
}
如何获取这些内容并将其放入新的 NSMutableDictionary 中?
I have an existing NSDictionary that has:
{
"charts_count" = 2;
"created_at" = "2010-04-12T16:37:32Z";
exchange = NASDAQ;
"followers_count" = 259;
id = 8404;
industry = "<null>";
"messages_count" = 1436;
ric = "GRPN.O";
sector = "<null>";
symbol = GRPN;
title = Groupon;
"updated_at" = "2011-09-05T04:17:56Z";
}
How can I take these contents and put it into a new NSMutableDictionary?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
-mutableCopy
。请注意,
-mutableCopy
返回id
(Swift 中的Any
),因此您需要分配/转换为正确的类型。它创建原始字典的浅表副本。Use
-mutableCopy
.Note that
-mutableCopy
returnsid
(Any
in Swift) so you will want to assign / cast to the right type. It creates a shallow copy of the original dictionary.如果是斯威夫特
In case of Swift
在 swift 3 中试试这个
Try this in swift 3
也有效,因为您将字典设置为不附加。您还可以使用:
获得相同的效果并附加到现有内容。
Also works, since you are setting the dictionary not appending. You can also use:
for the same effect and to append to existing content.