0

I'm new here. In my game an IBAction triggers setting a button's image. The device reacts with setting an image to another button. Depending on the situation the device sets a new image at its button. This all works so fast that the user only sees the last image. How can I interrupt the program sequence? I tested sleep(), timer, DispatchTime.now - but nothing works. I've made a little code, that describes my problem:

    `@IBAction func StartPressed(_ sender: Any) {
        Button1.setTitle("1", for: .normal)
        Thread.sleep(until: Date(timeIntervalSinceNow: 2.5))
        Button2.setTitle("2", for: .normal)
    }

` In this example the title text of both buttons is shown after 2.5 seconds from pressing the Start button. But the first button should show his title immediately and after 2.5 seconds the second button should show its title. I'm very grateful for every idea.

swifted
  • 9
  • 2
  • Use `asyncAfter`. For a convenient wrapper, see https://stackoverflow.com/questions/24034544/dispatch-after-gcd-in-swift/24318861#24318861 – matt Dec 09 '18 at 20:33
  • Thank you @matt! I've checked this. For more than two instructions only the method by Rahul Singha Roy at this site is working. But sometimes it's difficult to encapsulate bigger pieces of code. – swifted Dec 10 '18 at 18:50

0 Answers0