문제

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