I tried to write a program that displays a message when I press the button 10 times, but I got an expected declaration error in the if part.Please tell me how to solve this problem.
import UIKit
classViewController:UIViewController {
override func viewDidLoad(){
super.viewDidLoad()
// Do any additional setup after loading the view, typically from anib.
}
override funcdidReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
varCountNum = 10
@IBOutlet weak var label: UILabel!
@ IBAction func button (sender: AnyObject) {
label.text=String (CountNum)
CountNum --
}
ifCountNum == 0 {// Here is an error
label.text="0 now"
}
}
As I checked with you,
An Expected Declaration error occurs.
This is because we write directly within the class.
import UIKit
classViewController:UIViewController {
override func viewDidLoad(){
super.viewDidLoad()
// Do any additional setup after loading the view, typically from anib.
}
override funcdidReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
varCountNum = 10
@IBOutlet weak var label: UILabel!
@ IBAction func button (sender: AnyObject) {
label.text=String (CountNum)
CountNum --
}
// This is inside the class.
// if CountNum == 0 {
// label.text="0 now"
//}
}
That's why it's an error.
Be sure to write the if statement inside the function.
For programs that display a message after pressing the button 10 times,
import UIKit
classViewController:UIViewController {
override func viewDidLoad(){
super.viewDidLoad()
// Do any additional setup after loading the view, typically from anib.
}
override funcdidReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
varCountNum = 10
@IBOutlet weak var label: UILabel!
@ IBAction func button (sender: AnyObject) {
CountNum --
ifCountNum == 0 {
label.text="0 now"
} else {
label.text=String (CountNum)
}
}
}
I think this is a good idea.
610 Uncaught (inpromise) Error on Electron: An object could not be cloned
577 PHP ssh2_scp_send fails to send files as intended
568 Who developed the "avformat-59.dll" that comes with FFmpeg?
573 Understanding How to Configure Google API Key
600 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.