如何在数据后面的数组中初始化和添加值
(
[0] => Array
(
[name] => First element
[foo] => bar
)
[1] => Array
(
[name] => Second element
[foo] => bar2
)
)
答案 0 :(得分:13)
包含词典的那个数组,你在追求它吗?
let myArray = [["name": "First element", "foo": "bar"], ["name": "Second element", "foo": bar2]]
//在循环中编辑添加项目:
var myArray = [[String: String]]()
for i in 0..<10 {
let dict = ["name": "Item\(i)", "foo": "bar\(i)"]
myArray.append(dict)
}
print("\(myArray)")