0

I'm making an application where two buttons are moving. The first moves immediately and the second one moves after 1 second. What's happening now in my application is that when I click the start button before one second has passed, it shows two of the second button moving. I believe what I would have to do is that when the button is clicked, I would have to cancel the dispatch_after, but when I try to do this by writing this code:

let time1 = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW),1 * Int64(NSEC_PER_SEC))
dispatch_after(time1, dispatch_get_main_queue()) {
    // code of second button moving
}
if time1 == true
    {time1 = false}

it says that I cannot assign this to a dispatch_time. What should I do? This is the complete code if this helps you:

@IBAction func startbutton(sender: UIButton) {
// code for moving the first button
let time1 = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW),1 * Int64(NSEC_PER_SEC))
dispatch_after(time1, dispatch_get_main_queue()) {
    // code of second button moving
}
if time1 == true
    {time1 = false}
}
rmaddy
  • 298,130
  • 40
  • 468
  • 517
Anton O.
  • 633
  • 7
  • 25
  • A `dispatch_time` is not a boolean, so you can't compare it to `true` or `false` or assign those values to it. Perhaps more importantly, how are you animating these buttons? UIKit animations don't normally require GCD calls. – Tom Harrington Dec 17 '15 at 00:46
  • Ok I will update the question. – Anton O. Dec 17 '15 at 00:47

0 Answers0