gpt4 book ai didi

swift - 如何在swift中将字典添加到数组

转载 作者:搜寻专家 更新时间:2023-10-31 08:12:37 25 4
gpt4 key购买 nike

如何初始化数据并向数组添加值

(
[0] => Array
(
[name] => First element
[foo] => bar
)

[1] => Array
(
[name] => Second element
[foo] => bar2
)

)

最佳答案

这是一个包含字典的数组,是你要的吗?

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)")

关于swift - 如何在swift中将字典添加到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35453358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com