Quantcast
Viewing all articles
Browse latest Browse all 11

Answer by Dima G for Prevent multiple Tap on the same UIButton

In Swift, you can also use defer keyword, to execute a block of code that will be executed only when execution leaves the current scope.

@IBAction func btnAction(_ sender: UIButton) {    sender.isUserInteractionEnabled = false    defer {        sender.isUserInteractionEnabled = true    }    // rest of your code goes here}

Note: This will only be helpful if the "rest of your code" is not async, so that the execution actually leaves the current scope. In async cases you'd need to set isUserInteractionEnabled = true at the end of that async method.


Viewing all articles
Browse latest Browse all 11

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>