本文介绍了我一直在Swift中遇到这个错误。 “在一条线上的连续声明必须分开';'”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,非常感谢任何帮助谢谢!这是用Swift中的Xcode编写的。我一直收到错误,指出一条线上的连续声明必须被'分隔';'
Here is my code, any help is much appreciated thank you! This was written in Xcode in Swift. 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..."
}
推荐答案
看起来你在类名中的View和Controller之间有一个额外的空格,而且还有很多缺少的右括号。
Looks like you had an extra space between View and Controller in the class name and also a lot of missing closing parentheses.
试试这个:
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
}
}
}
}
这篇关于我一直在Swift中遇到这个错误。 “在一条线上的连续声明必须分开';'”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!