【发布时间】:2016-05-27 16:25:53
【问题描述】:
我有一个包含多个字典数据的字典:
{
1455201094707 = {
};
1455201116404 = {
}:
1455201287530 = {
};
}
我必须迅速将所有这些字典添加到一个数组中。 如何将字典迭代为:
for let tempDict in dataDictionary
{
self.tempArray.addObject(tempDict)
}
错误“让模式不能出现嵌套在一个已经不可变的 上下文”
for tempDict in dataDictionary as! NSMutableDictionary
{
self.tempArray.addObject(tempDict)
}
错误:参数类型元素(又名(键:AnyObject,值:AnyObject)) 参数类型不符合预期类型anyobject
for tempDict in dataDictionary as! NSMutableDictionary
{
self.tempArray.addObject(tempDict as! AnyObject)
}
错误:无法转换类型 '(Swift.AnyObject, Swift.AnyObject)' (0x1209dee18) 到 'Swift.AnyObject' (0x11d57d018)。
for tempDict in dataDictionary
{
self.tempArray.addObject(tempDict)
}
错误:AnyObject 类型的值没有成员生成器
编辑
我希望最终的数组为:
(
{
1455201094707 = {
};
}
{
1455201116404 = {
}:
}
)
实现这一点的正确方法是什么?
任何帮助将不胜感激.....
我用过代码:
var tempArray:[NSDictionary] = []
for (key, value) in tempDict {
tempArray.append([key : value])
}
错误:AnyObject 类型的值不符合预期的字典键类型 NSCopying
代码:
let tempArray = tempDict.map({ [$0.0 : $0.1] })
错误:表达式类型不明确,没有更多上下文
【问题讨论】:
标签: ios arrays iphone swift dictionary