ios - Swift - Printing out the current value of a number -
i'm developing counter app every time press button count up. have done , works 100%, i'm trying make button , when press it, shows current number on console prints out 0
because that's default variable assigned value to.
my whole class:
var counternumber = 0 @iboutlet weak var counterlabel: uilabel! func initcount(){ counternumber = 0 } func numberup(){ self.counternumber++; counterlabel.text = "\(self.counternumber)" } @ibaction func countup(sender: uibutton) { numberup() } @ibaction func restartbutton(sender: uibutton) { initcount() } @ibaction func printbutton(sender: uibutton) { self.numberup(); print(self.counternumber) } override func viewdidload() { super.viewdidload() initcount() } override func didreceivememorywarning() { super.didreceivememorywarning() }
}
just call method numberup
in printbutton:
action.
var counternumber = 0//this variable of class @iboutlet weak var counterlabel: uilabel! @ibaction func printbutton(sender: uibutton) { self.numberup(); print(self.counternumber) } func numberup(){ self.counternumber++; counterlabel.text = "\(self.counternumber)" }
Comments
Post a Comment