2016-07-18 15 views
0

第一次構建一個應用程序,所以請原諒,如果這是一個微不足道的修復。我已經在youtube上尋找幫助,使用Google搜索,並搜索StackOverflow,但是在嘗試構建時似乎沒有修復錯誤。有人能夠看看我告訴我哪裏出錯了嗎?看看這個工作副本我找不到差異= \測驗應用程序 - 連續聲明錯誤

我得到的錯誤是(主要是案例2 /案例3行): - 行上的連續陳述必須由' ;」 -Expected表達 - 使用未解決的識別符「RandomQuestions」 - 使用未解決的識別符的「外殼2」(和「情況下3」)

import UIKit 

class ViewController: UIViewController { 

    @IBOutlet weak var QuestionLabel: UILabel! 

    @IBOutlet var Button1: UIButton! 
    @IBOutlet var Button2: UIButton! 
    @IBOutlet var Button3: UIButton! 
    @IBOutlet var Button4: UIButton! 

    var CorrectAnswer = String() 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 

     RandomQuestions() 

    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    func RandomQuestioins(){ 

     var RandomNumber = arc4random() % 4 
     RandomNumber += 1 


     switch(RandomNumber){ 
     case 1: 

      QuestionLabel.text = "Hello World, What Is My Name?" 
      Button1.setTitle("John", forState: UIControlState.Normal) 
      Button2.setTitle("Ryan", forState: UIControlState.Normal) 
      Button3.setTitle("Alex", forState: UIControlState.Normal) 
      Button4.setTitle("Google", forState: UIControlState.Normal) 
      CorrectAnswer = "2" 
      break 
     case2: 

      QuestionLabel.text = "What country do you live in?" 
      Button1.setTitle("Russia", forState: UIControlState.Normal) 
      Button2.setTitle("Good Question", forState: UIControlState.Normal) 
      Button3.setTitle("USA", forState: UIControlState.Normal) 
      Button4.setTitle("Mexico", forState: UIControlState.Normal) 
      CorrectAnswer = "3" 
      break 
     case3: 

      QuestionLabel.text = "What day is it?" 
      Button1.setTitle("Saturday", forState: UIControlState.Normal) 
      Button2.setTitle("Sunday", forState: UIControlState.Normal) 
      Button3.setTitle("Monday", forState: UIControlState.Normal) 
      Button4.setTitle("Thusday", forState: UIControlState.Normal) 
      CorrectAnswer = "2" 
      break 
     case 4: 
      QuestionLabel.text = "What is your favorite color?" 
      Button1.setTitle("Blue", forState: UIControlState.Normal) 
      Button2.setTitle("Red", forState: UIControlState.Normal) 
      Button3.setTitle("Green", forState: UIControlState.Normal) 
      Button4.setTitle("Yellow", forState: UIControlState.Normal) 
      CorrectAnswer = "1" 

      break 
     default: 

      break 
     } 

    } 




    @IBAction func Button1Action(sender: AnyObject) { 

     if (CorrectAnswer == "1"){ 

      NSLog("Correct") 
     } 
     else{ 
      NSLog("Try Again!") 
     } 
    } 
    @IBAction func Button2Action(sender: AnyObject) { 
     if (CorrectAnswer == "2"){ 

      NSLog("Correct") 
     } 
     else{ 
      NSLog("Try Again!") 
     } 
    } 
    @IBAction func Button3Action(sender: AnyObject) { 
     if (CorrectAnswer == "3"){ 

      NSLog("Correct") 
     } 
     else{ 
      NSLog("Try Again!") 
     } 
    } 
    @IBAction func Button4Action(sender: AnyObject) { 
     if (CorrectAnswer == "4"){ 

      NSLog("Correct") 
     } 
     else{ 
      NSLog("Try Again!") 
     } 
    } 


} 

回答

0

未解決的標識符只是意味着你沒有定義的變量,因此XCode不知道你在找什麼。

在你的情況,你離開了案例2和案例3之間的空間,它應該是case 2:

而且,一般函數名稱應當是駱駝的情況下(與第一個字符爲小寫),所以這將是如果可以將RandomQuestions()重命名爲randomQuestions(),那就太好了。並嘗試以「doSomething」方式命名您的函數,如setRandomQuestions或generateRandomQuestions()

+0

非常感謝您的評論!只要你指出,我很快就看到了我做錯了什麼。似乎很明顯,現在哈哈只是缺乏對細節的關注。 – Babou16

+0

嗯,你確實提到你是新的,每個人都從某個地方開始。保持 :) – Happiehappie