Block in serial dispatch queue not executing - GCD iOS Objective-C

I've got a for loop enqueuing blocks on to the main queue as follows:

  for (int x=0; x<5; x++) {
    double delayInSeconds = x * .03;
      dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
      dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        ... code here ...
      }
  }

Only the first block gets executed. I've verified that the loop is working properly, it is looping the proper number of times and no exceptions or error are raised.

Answers


With this code:

for (int x=0; x<5; x++) {
    double delayInSeconds = x * .03;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        NSLog(@"Blah!!");
    });
}

"Blah" gets logged out 5 times. I'm guessing the code you posted isn't identical to the code you have in the app? I had to add the ); to the end of the dispatch_after call.


Need Your Help

VBA Excel - Run-time Error '1004' when trying to assign a value to a Cell

excel vba excel-vba cells

For the background, see my previous question. ((I have posted the same code earlier but with different problems. However, this is a new problem that I have encountered.)

IOS send pause video to html5

javascript ios html5 uiwebview html5-video

I have a little problem on IOS native send data to Html5.