gpt4 book ai didi

ios - 我在 Swift 中不断收到此错误。 "Consecutive Declarations On A Line Must Be Separated By ' ;'"

转载 作者:搜寻专家 更新时间:2023-10-30 22:14:26 25 4
gpt4 key购买 nike

这是我的代码,非常感谢任何帮助,谢谢!这是在 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 之间有一个额外的空格,并且还缺少很多右括号。

试试这个:

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

关于ios - 我在 Swift 中不断收到此错误。 "Consecutive Declarations On A Line Must Be Separated By ' ;'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26132157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com