我不断收到这个错误在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..." }
看起来你在类和名称之间的View和Controller之间有一个额外的空间,还有很多缺less的左括号。
尝试这个:
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 } } } }
var Hello: UILabel! {
这条线看起来错了。 去掉它。
编辑
最后还有}
失踪。
正确缩进你的代码将有助于发现这样的错误!
编辑2
哦,我想你的意思是class ViewController
而不是class View Controller
。