Reputation: 105
How to get the number of times the screen be touched in swift I don't
know which method to use, please help
Upvotes: 2
Views: 2747
Reputation: 501
Create static var counter = 0
Counter should be static variable.
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
counter++
print(counter)
}
Upvotes: 0
Reputation: 848
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)
}
Upvotes: 3