gpt4 book ai didi

ios - 如何在结构数组中插入数字(Swift4)

转载 作者:搜寻专家 更新时间:2023-11-01 06:31:36 25 4
gpt4 key购买 nike

我的代码不工作。我要做的就是将数字插入到结构的内部数组中。现在这不起作用:

@IBAction func move(_ sender: Any) {
bad.numbers.insert(0, at: 0)
}


struct bad {
var numbers: [Int] = [1, 2, 3]
}

最佳答案

您需要将数字属性声明为静态的。顺便说一下,以大写字母开头命名结构是 Swift 的惯例:

struct Bad {
static var numbers: [Int] = [1, 2, 3]
}

要在索引 0 处插入元素,您需要这样调用它:

Bad.numbers.insert(0, at: 0)

print(Bad.numbers) // "[0, 1, 2, 3]\n"

关于ios - 如何在结构数组中插入数字(Swift4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46556159/

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