2

How to get the number of times the screen be touched in swift I don't

know which method to use, please help

  • Do yo mean number of touches on the screen at the time or number of taps? – ZeMoon Mar 03 '16 at 08:38
  • Check this http://stackoverflow.com/questions/26829295/swift-getting-the-coordinates-from-the-location-i-touch-the-touchscreen/34735546#34735546 – kb920 Mar 03 '16 at 08:43

2 Answers2

3

It is quite simple, just declare a counter at top, var counter = 0

then use the function, just type touchesBegan it will show

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    counter++
    print(counter)
}
Lee
  • 850
  • 11
  • 23
0

Create static var counter = 0
Counter should be static variable.

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
counter++
print(counter)
}
Avinash Jadhav
  • 491
  • 4
  • 17