AFNetworking/AFNetworking — pull request #127 by zbowling (2011-11-24 03:58:36+00:00)
Title: Improved AFURLConnectionOperation and AFHTTPRequestOperation designed around NSBlockOperation's execution blocks

In order to solve a few suttle bugs and issues, we refactored at SeatMe the AFURLConnectionOperation class to make similar to the NSBlockOperation design.

We need operations not to finish mark they are finished until the entire operation was ready to extract data from it. Because we have dependent operations that expect that the operation had finished and left things in a certain state (in our case that they had successfully written something to our database), before the next dependent operation that worked off that data should start.

To solve this we refactored AFURLConnectionOperation to have a model similar to NSBlockOperation which takes exectionBlocks that will fire inside the concurrent operation before the operation is marked as finished. Execution blocks are processed using a shared concurrent dispatch queue after the NSURLConnection has successfully downloaded all data.

This actually solves two stones in one pass because the subclassed operations that do processing on their own (like AFJSONRequestOperation, AFXMLRequesetOperation, AFXMLDocumentRequestOperation, AFPropertyListRequestOperation, AFImageRequestOperation) which can now just register another execution block to process their outputs. This removes the need for our previous method we had in our branch at doing it this with partly with a method that the subclasses had to override provided by AFHTTPRequestOperation.

This also allows us to add an execution block that does work for us with the response inside the operation without subclassing, like save the output to a database or queue it up for display. Since the block isn't marked as finished at this point, dependent operations can expect work they needed to be completed before they start is completely done. (Before we understood this was an issue, in our code we were using our own NSConditional locks around the completion callback because performAllAndWait wasn't working as intended).

This also solves a few other smaller bugs around using NSOperationQueue when using dependencies since it allows a NSOperation to have ```isCancalled == YES``` while also having ```isExecuting == YES``` and before ```isFinished``` is set to YES to allow the operation to fully close out.

At the AFHTTPRequestOperation level, this branch also doesn't break anyone that still wants to set completionBlock on NSOperation or change it's behavior in any real way. It introduces a new finishedBlock property which works similarly to the completionBlock but instead returns on the calling queue that created the block by default (but also is configurable with the callbackQueue property).

This removes the setCompletionBlockWithSuccess:Failure since they broke the user's own use of using completionBlock and didn't work consistently across subclasses (returning different types each time). However the finishedBlock property should be a usable replacement for this instead.

This branch also improves performance slightly in a few small places, fixes a brew crashing issues ([[... retain] autorelease] of returns), and contains the support for iOS Multitasking that we sent a pull request for earlier, and some other minor changes.

Thanks!