gpt4 book ai didi

xcode - 即使我在 Swift、Xcode 6 中声明,也会出现 switch 'expected declaration' 错误

转载 作者:行者123 更新时间:2023-11-30 10:21:03 25 4
gpt4 key购买 nike

我收到一条错误消息,指出 switch 语句出现“预期声明” https://www.dropbox.com/s/3cjeo3sxg0zw431/Screen%20Shot%202014-10-30%20at%2001.01.48.png?dl=0

let questionSelected = Int(arc4random_uniform(1))


switch questionSelected{
case 0:
let x = "(question goes here)"
}

最佳答案

案例必须详尽,否则您必须有默认声明。我修改了 case 0: 只是为了让它在 Playground 中执行。

let questionSelected = Int(arc4random_uniform(1))


switch questionSelected{
case 0:
let x = "(question goes here)"
default:
break
}

好吧,又迈出了一步。这有效。将标签连接到 Storyboard。

class ViewController: UIViewController {


@IBOutlet weak var questionBox: UILabel!


override func viewDidLoad() {
super.viewDidLoad()

let questionSelected = Int(arc4random_uniform(1))

switch questionSelected{
case 0:
questionBox.text = "Does this work?"
default:
questionBox.text = "Does this work better?"
}

}
}

第二次更新:

func thisCodeMustBeInAFunction() {

let questionSelected = Int(arc4random_uniform(1))

switch questionSelected{
case 1:
questionBox.text = "(question goes here)"
default:
break
}
}

关于xcode - 即使我在 Swift、Xcode 6 中声明,也会出现 switch 'expected declaration' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26643222/

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