Ahmed Assem Mostafa
Ahmed Assem Mostafa

Reputation: 105

How to Count the number of times the screen be touched in swift?

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

Answers (2)

Avinash Jadhav
Avinash Jadhav

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

Lee
Lee

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

Related Questions