swift - Adding and Displaying Integers in a Label -
i'm making scoring app can keep track of score different board games or such playing. here code have far.
override func viewdidload() { super.viewdidload() } @iboutlet weak var scoretextfield: uitextfield! @iboutlet weak var scoretotal: uilabel! @ibaction func buttonpressed(sender: anyobject) { if let number = int(scoretextfield.text!){ scoretotal.text = "\(number)" } }
i want able type in textfield , when button pressed add both previous number , 1 in textfield , display result in label. can me please? thank you!
if let number = int(scoretextfield.text!){ let previousscoretext = scoretotal.text if previousscoretext == nil || previousscoretext.isempty == true { previousscoretext = "0" } scoretotal.text = "\(int(previousscoretext!)! + number)" }
Comments
Post a Comment