A Modern Network Operation
Fortunately, I have recently worked on a design that I have been quite pleased with. In this design I am happily using
NSOperationsubclasses again and I am using theNSURLSessionAPI.[…]
Note that I am triggering a KVO notification on
isFinishedas opposed tofinishedwhich is what the property name is. This seems to be a Swift-ism as theNSOperationget accessor is calledisFinishedinstead ofgetFinishedand I suspect that is part of why I need to tickle the accessor name instead of the property name.[…]
By using
NSOperationsubclasses I can now prioritize my network calls (posting to twitter is a higher priority than receiving avatars from twitter for example), cancel operations that are no longer needed (avatars or images that are no longer on screen) and in general be a much better citizen by only keeping the radios on for as long as I need them and not any longer.Further, I can now watch for application life-cycle events in my
NetworkControllerand terminate operations when my application goes into the background, further improving my citizenship status. I can also look for operations that need to finish when the application goes into the background and request additional background time.