Advanced NSOperation & Earthquakes

One of my favorite sessions at WWDC was Advanced NSOperations. I've been attempting to run the Earthquakes App (XCode 7, IOS 9 Device) and it runs but nothing appears at the outset except for an empty UITableView. Dragging down to attempt to refresh the table brings up a network activity indicator but then the application crashes.


The only changes I made to the demo code were to change the bundle identifier and check the box to allow it to run upside down (in order to eliminate a warning).


Anyone have a similar ill-fated experience?

Update:


I've been able to run in the Simulator. The App still opens to an empty UITableView but the drag to refresh gesture seems to run correctly. I am seeing the the Network Activity indicator is still active after the UITableView data has been loaded.

Accepted Answer

Yes, the Network Activity Indicator not disappearing is one of two known bugs that slipped through.


It's pretty easy to fix: just negate the "self?.isCancelled == true" line in the private Timer class.


The other bug is similar, in NegatedCondition's evaluateForOperation... method. Ironically, the logic in there is negated. 😉

Hi Dave,


I'm wondering what are the best practices for passing data between NSOperations. In sample code, you create URL to file in cache directory, which URL you pass to two operations. First operation fetches earthquakes and saves data to this URL, second operation takes data from this URL and parse it. Although I find this concept interesting I believe that it is not always convenient to pass data like this.


Let's discuss one example. Let's say I have an operation A that wraps object insertion to CoreData. Then I have some operation B that is supposed to do some additional work on that inserted object. I initliaze both operations and make B dependent on A (B.addDependency(A)). After that I'm adding these to the queue. How should I pass that inserted object from A to B? The best way would be to pass this object during initialization (like you pass URL to a resource) but of course that object doesn't exist until A finishes its work. Setting this object in B in some completion handler doesn't seem right. But.. maybe it is?


What are the best practices for passing data between operations?

Dave,


Thanks for taking the time to keep us updated.


I've since modified the logic, though I must admit that your explanation of the fix to the NegatedCondition bug required that I read and re-read the purpose of the class before I realized what you meant. In this case should actually be looking for errors, i.e.

result.error != nil

as opposed to

result.error == nil

Hi Nagan,


I'm exactly in that trouble right now.

I have a group operation with 3 sub operations. Two (A and B) are for collecting some information and the third (C) should than handle/display this informations.

I made C dependent of A & B. But now I'm not sure how to pass the infos to C.


Did you find out a proper way to do that?

You bring up an interesting point. If you're working with CoreData objects could you pass the NSManagedObjectID to the subsequent operatioin(s)? Because operations are going to be running on different threads it's probably best to not pass object refrences around anyway.

Just wanted to revist this thread now that 7.0 and 7.1 are out. Any updates to the source?

Advanced NSOperation & Earthquakes
 
 
Q