我在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)"
}

最佳答案

这些情况必须详尽无遗,否则您必须具有默认语句。我修改了案例0:只是为了让它在操场上执行。

let questionSelected = Int(arc4random_uniform(1))


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


好吧,又走了一步。这可行。将标签连接到情节提要。

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
     }
}

09-25 19:19