2014-10-01 9 views
5

Ecco il mio codice, ogni aiuto è molto apprezzato grazie! Questo è stato scritto in Xcode in Swift. Continuo a ricevere l'errore che indica "Dichiarazioni consecutivi su una linea devono essere separati da ';'"Continuo a ricevere questo errore in Swift. "Le dichiarazioni consecutive su una riga devono essere separate da"; ""

 import UIKit 

class View Controller: UIViewController { 
@IBOutlet var outputLabel: UILabel! = UILabel() 

var currentCount : Int = 0 

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

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


@IBAction func addOneButton(sender: UIButton) { 

    currentCount = currentCount + 1 
    if(currentCount <= 1) { 
     outputLabel.text = "The button has been clicked 1 time!" 
    outputLabel.textColor = UIColor.purpleColor() 
    } 
    else { 
    outputLabel.text = "The button has been clicked \(currentCount) number of times." 
    outputLabel.textColor = UIColor.redColor() 


     var Hello: UILabel! { 
      if(currentCount >= 5) { 
       outputLabel.text = "Don't Forget To Give A GOOD Rating! :D" 
      outputLabel.textColor = UIColor.orangeColor() 
      } 
      else { 
       outputLabel.text = "Nothing To See Here..." 
       } 
+0

Quale linea si ottiene l'errore? –

risposta

4

Sembra che ci sia uno spazio aggiuntivo tra Visualizza e Controller nel nome della classe e anche molte parentesi di chiusura mancanti.

Prova questo:

import UIKit 

class ViewController: UIViewController { 
    @IBOutlet var outputLabel: UILabel! = UILabel() 

    var currentCount : Int = 0 

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

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


    @IBAction func addOneButton(sender: UIButton) { 

     currentCount = currentCount + 1 
     if(currentCount <= 1) { 
      outputLabel.text = "The button has been clicked 1 time!" 
      outputLabel.textColor = UIColor.purpleColor() 
     } 
     else { 
      outputLabel.text = "The button has been clicked \(currentCount) number of times." 
      outputLabel.textColor = UIColor.redColor() 

      var Hello: UILabel! { 
       if(currentCount >= 5) { 
        outputLabel.text = "Don't Forget To Give A GOOD Rating! :D" 
        outputLabel.textColor = UIColor.orangeColor() 
       } 
       else { 
        outputLabel.text = "Nothing To See Here..." 
       } 
       return outputLabel 
      } 
     } 
    } 
} 
+0

In realtà non ha funzionato, ha avuto un errore sulla quarta riga. –

+0

Sono contento di averlo risolto. Accertati di accettare le risposte che ti sono utili. È molto apprezzato –

+0

Potresti aiutarmi ancora, c'è ancora un errore nella quarta riga che dice "Ritorno mancante in una funzione che si prevede di restituire UILabel!" –

0
var Hello: UILabel! { 

Questa linea sembra sbagliato. Rimuoverla.

Modifica

Ci sono anche } mancano alla fine.
Il rientro corretto del codice aiuterà a individuare molto facilmente tali errori!

Edit 2

Oh, e credo che si intende class ViewController invece di class View Controller.

+0

Ho provato a rimuovere quella linea, ha creato più errori. Inoltre, questo è l'identificazione per un'etichetta con testo, quindi non ho scritto quella riga Xcode lo fa per te. Grazie per la risposta. –

+0

Qual è lo scopo di 'var Hello: UILabel! { '? Il codice non ha alcun senso al momento. Sono sorpreso che Xcode lo compili anche. – fluidsonic

+0

Quando ho aggiunto una nuova etichetta, l'opzione l'ho trascinata sull'esecutore per scrivere il codice per esso, che credo fosse che dovresti fare. –

Problemi correlati