【发布时间】:2016-07-10 09:19:53
【问题描述】:
我正在使用嵌套字典数据结构来跟踪一组NSLayoutConstraints,具体而言[String: [String: NSLayoutConstraint]]。但是对于我的情况,让我们考虑以下更简单的示例:
var myNestedDictionary = [String: [Int: Double]]()
myNestedDictionary["squares"] = [1: 1.0, 2: 4.0, 3: 9.0, 4: 16.0]
myNestedDictionary["cubes"] = [1: 1.0, 2: 8.0, 3: 27.0, 4: 64.0]
myNestedDictionary["factorials"] = [1: 1.0, 2: 2.0, 3: 6.0, 4: 24.0]
如何将所有值提取到[Double]中,不是一个字典条目的键-值对,例如我如何从myNestedDictionary["cubes"] 获得[1.0, 8.0, 27.0, 64.0]?
【问题讨论】:
标签: swift dictionary data-structures nested