Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When you first posted <a href="https://stackoverflow.com/questions/20224811/nsoperationqueue-trouble-understanding-the-order">your other question</a>, I guessed you might have been dealing with asynchronous network requests, and if you want operations with asynchronous network requests, one generally solves that wrapping such network request within a subclassed <code>NSOperation</code> <a href="https://stackoverflow.com/a/20225013/1271826">as I discussed in the answer to your other question</a> (and as ilya subsequently also described here). </p> <p>Your question here suggested that you are calling <code>sendSynchronousRequest</code>. If that was all you were doing, then that <code>NSOperation</code> subclassing pattern would not be needed, and you should be able to use <code>addDependency</code> without incident. But, it looks like you discovered that <code>getDataWithURL</code> was, itself, submitting that <code>sendSynchronousRequest</code> to its own operation queue, effectively making it asynchronous. You correctly identified that if you get rid of that redundant operation queue logic from within <code>getDataWithURL</code>, then then your problem is resolved and no <code>NSOperation</code> subclassing is needed.</p> <p>But, I wouldn't be too quick to dismiss this subclassed <code>NSOperation</code> pattern, though, because <code>sendSynchronousRequest</code> has some limitations with which you might to encumber yourself. Namely, those requests can't be canceled. Likewise, you can't get progress of those requests as they're underway, nor handle any advanced features like challenge-response authentication or the like. You might not need any of these features, but because of these limitations, many of us generally shy away from <code>sendSynchronousRequest</code> (and <code>sendAsynchronousRequest</code>, too).</p> <p>Longer term, you might find yourself drawn to <a href="https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLConnectionDataDelegate_protocol/Reference/Reference.html" rel="nofollow noreferrer"><code>NSURLConnectionDataDelegate</code></a>-based network calls which addresses these limitations. In which case, this <code>NSOperation</code> subclass pattern may again become useful. Or, even better, consider using a framework like <a href="https://github.com/AFNetworking/AFNetworking" rel="nofollow noreferrer">AFNetworking</a> that provides an <code>NSOperation</code>-based networking solution, but does a lot of this grunt work for you.</p>
 

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