我有一个现有的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?
使用-mutableCopy
。
NSDictionary *d;
NSMutableDictionary *m = [d mutableCopy];
需要注意的是-mutableCopy
返回id
(斯威夫特Any
),所以你会想分配/强制转换为正确的类型。它创建原始字典的浅拷贝。
在斯威夫特的情况下,
var tempDic: NSMutableDictionary = yourDictionary.mutableCopy() as NSMutableDictionary
在迅速3试试这个
let mutableDic: NSMutableDictionary = (yourDictionary as! NSDictionary).mutableCopy() as! NSMutableDictionary