0

I am using Swift 2.0 and I am trying to make a simple app with a counter. So every time I press a button, the count of a label is supposed to go up one by one. I cannot figure out how to make this kind of loop. I have been really confused about this because Xcode tells me strings and integers do not go together. What should happen is when I press the button, the String will change from 1 to 2, then if I press it again it will go from 2 to 3. So could you give some examples of how to do this? Please help me and give a bit explanations of how it works and why. Thanks in advance.

1
  • 1
    StackOverflow isn't a tutorial site. You should be able to find other material on the internet from where you can learn the basics of Swift. Commented Sep 17, 2015 at 20:04

1 Answer 1

2

I would use an internal counter and an ibaction

var counter : Int = 0

@IBOutlet weak var PlusButton : UIButton?
@IBOutlet weak var Numbertoshow : UILabel?


@IBAction func UseCurrentLoc(sender: UIButton) {
    counter++
    Numbertoshow!.text="\(counter)"

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.