Note that there are some explanatory texts on larger screens.

plurals
  1. PONSOperationQueue with synchronous NSURLConnection
    primarykey
    data
    text
    <p>Building on an <a href="https://stackoverflow.com/questions/20224811/nsoperationqueue-trouble-understanding-the-order">earlier</a> question: I have an <code>NSOperationQueue</code> that looks like this:</p> <pre><code>NSBlockOperation *block1 = [NSBlockOperation blockOperationWithBlock:^{ [someObject someSelector]; }]; NSBlockOperation *block2= [NSBlockOperation blockOperationWithBlock:^{ [someObject anotherSelector]; }]; [block2 addDependency:block1]; [queue addOperation:block1]; [queue addOperation:block2]; </code></pre> <p>Now, inside <code>someSelector</code> I have:</p> <pre><code>returnData = [requesterObj getDataWithURL:(NSString*)url]; </code></pre> <p>where <code>getDataWithURL</code> contains something like:</p> <pre><code>NSURL *requestUrl = [NSURL URLWithString:strUrl]; NSMutableURLRequest *request = [NSMutableURLRequest requestUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:timeout]; NSError *requestError; NSURLResponse *urlResponse = nil; NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;urlResponse error:&amp;requestError]; </code></pre> <p>Now, when I add breakpoints, it appears that the second block is being called before the <code>NSURLConnection</code> from the first block finishes. Presumably because the call to <code>getDataWithURL</code>, is itself asyncronous. What's the best way to make sure that the first block doesn't complete before that request returns. Should I try using an <code>NSInvocation</code> to put the data inside <code>returnData</code>?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload