我一直在Swift中遇到这个错误。 "一条线上的连续声明必须由';'"

时间:2014-10-01 00:01:13

标签: ios swift

这是我的代码,非常感谢任何帮助谢谢!这是用Swift中的Xcode编写的。我一直收到错误,指出“一条线上的连续声明必须被'分隔';'”

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

2 个答案:

答案 0 :(得分:4)

看起来你在类名中的View和Controller之间有一个额外的空格,而且很多都没有关闭括号。

试试这个:

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

答案 1 :(得分:0)

    var Hello: UILabel! {

这条线看起来不对劲。删除它。

修改

最后还有}失踪 正确缩进代码将有助于发现这些错误!

编辑2

哦,我想你的意思是class ViewController而不是class View Controller