質問

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 ?

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top