Question

I'm using blocks inside a NSOperation. The main method of my NSOperation looks like this:

- (void) main {

    [self callMethodOfALiraryUsingCompletionBlock:^() {
       //this method takes time to execute, will call this block when done
    }];
}

I'd like my NSOperationto terminate when what's inside the block is done. Currently, it returns directly, before what's inside the block is executed ... Any idea how I can solve this ?

Was it helpful?

Solution

Little detail in your question, here is one possible outline which may help:

  • Create a semaphore (dispatch_semaphore_create)
  • Execute your library code asynchronously (dispatch_async)
  • Have the completion block for your library code signal the semaphore
  • Have your main method wait on the semaphore

HTH

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top