gpt4 book ai didi

swift - 错误 : '...' is not a prefix unary operator

转载 作者:可可西里 更新时间:2023-11-01 02:03:15 26 4
gpt4 key购买 nike

代码:

let names = ["Anna", "Alex", "Brian", "Jack"]
for name in names[...2] {
print(name)
}

错误:

Playground execution failed: error: MyPlayground.playground:3:19: error: '...' is not a prefix unary operator
for name in names[...2] {

我是 swift 的新手,因此非常感谢任何相关链接或任何类型的帮助。使用 swift 4

最佳答案

正如 Martin 和其他人所说,这在 Swift 4 中有效。在早期版本中,您可能想使用它:

let names = ["Anna", "Alex", "Brian", "Jack"]
for name in names[0..<3] {
print(name)
}

关于swift - 错误 : '...' is not a prefix unary operator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44921302/

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