Question: I know this sounds wrong! but what I need to achieve is to run a huge enumeration on the main thread and that will obviously block the whole app. What I'm looking for is kind of a animation or delay between the loop cycles so that other codes can get a chance to execute.
Here's my code:

```
for (NSTextCheckingResult* match in matchedArray) {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self addAttributes:@{NSBackgroundColorAttributeName:[UIColor redColor]} range:match.range];
    });
}

```

As mentioned on the comments this code is UI related that it has to run on the main thread.

I also tried `dispatch_after` but it seems like it will block the thread on the waiting time. is there anyway that I can do this or do I have to rework my whole logic?!

Answer: 
As you are running on the main thread each element in your `matchedArray` is processed sequentially. Therefore you can achieve the interleaving you wish with other tasks on the main queue by dispatching a block to process element *n* of the array which after doing its task dispatches a block to process element *n + 1*.

Something along the lines of (all code typed directly into answer):

```
- (void) processIndex:(NSUInteger)index ofArray:(NSArray *)matchedArray
{
   NSTextCheckingResult *match = matchedArray[index++];
   [self addAttributes:@{NSBackgroundColorAttributeName:[UIColor redColor]}
                 range:match.range];
   if(index < matchedArray.count)
      dispatch_async(dispatch_get_main_queue(),
                     ^{ [self processIndex:index ofArray:matchedArray]; });
}

...

if (matchedArray.count > 0)
   dispatch_async(dispatch_get_main_queue(),
                  ^{ [self processIndex:0 ofArray:matchedArray]; });

```

HTH
Like the other commenters, I too share a skepticism about the "should" run on the main thread claim, but I'll give you the benefit of the doubt that you understand your circumstances better than I...

You could write your "huge enumeration" to store intermediate states in some kind of variable or struct, have it run for X number of iterations, and then use a completion handler to place a delayed call `[self performSelector:@selector(crazyEnumerationMethod:) withObject:nil afterDelay:2.0]:`

You'd have to devise some kind of flag to flip once all the data was processed to your satisfaction which would prevent the method from firing again.

Essentially you'd be iterating over your data-set multiple times, with a pause in the action every iteration, until finally all the data was processed and the flag flips to prevent anymore iterations.

Depending on what your "huge enumeration" entails, this could be an extremely non-trivial process to write, but you never know, maybe there is a clean and clever way to store intermediate states and pick up where you left off on each iteration.