[英]I keep getting this error in Swift. “Consecutive Declarations On A Line Must Be Separated By ';'”
Here is my code, any help is much appreciated thank you! 这是我的代码,非常感谢任何帮助谢谢! This was written in Xcode in Swift.
这是用Swift中的Xcode编写的。 I keep getting the error that states "Consecutive Declarations On A Line Must Be Separated By ';'"
我一直收到错误,指出“一条线上的连续声明必须分开';'”
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..."
}
Looks like you had an extra space between View and Controller in the class name and also a lot of missing closing parentheses. 看起来你在类名中的View和Controller之间有一个额外的空间,还有很多缺少的右括号。
Try this: 试试这个:
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! {
This line looks wrong. 这条线看起来不对。 Remove it.
去掉它。
Edit 编辑
There are also }
missing at the end. 最后也有
}
失踪。
Correctly indenting your code will help spotting such errors a lot! 正确缩进代码将有助于发现这些错误!
Edit 2 编辑2
Oh and I guess you mean class ViewController
instead of class View Controller
. 哦,我猜你的意思是
class ViewController
而不是class View Controller
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.