{"id":13366,"date":"2016-01-29T15:10:47","date_gmt":"2016-01-29T20:10:47","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=13366"},"modified":"2016-01-29T15:11:35","modified_gmt":"2016-01-29T20:11:35","slug":"a-modern-network-operation","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/01\/29\/a-modern-network-operation\/","title":{"rendered":"A Modern Network Operation"},"content":{"rendered":"<p><a href=\"http:\/\/www.cimgf.com\/2016\/01\/28\/a-modern-network-operation\/\">Marcus Zarra<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.cimgf.com\/2016\/01\/28\/a-modern-network-operation\/\">\n<p>Fortunately, I have recently worked on a design that I have been quite pleased with.  In this design I am happily using <code>NSOperation<\/code> subclasses again and I am using the <code>NSURLSession<\/code> API.<\/p>\n<p>[&#8230;]<\/p>\n<p>Note that I am triggering a KVO notification on <code>isFinished<\/code> as opposed to <code>finished<\/code> which is what the property name is. This seems to be a Swift-ism as the <code>NSOperation<\/code> get accessor is called <code>isFinished<\/code> instead of <code>getFinished<\/code> and I suspect that is part of why I need to tickle the accessor name instead of the property name.<\/p>\n<p>[&#8230;]<\/p>\n<p>By using <code>NSOperation<\/code> subclasses 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.<\/p>\n<p>Further, I can now watch for application life-cycle events in my <code>NetworkController<\/code> and terminate operations when my application goes into the background, further improving my citizenship status.  I can also look for operations that <strong>need<\/strong> to finish when the application goes into the background and request additional background time.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Marcus Zarra: Fortunately, I have recently worked on a design that I have been quite pleased with. In this design I am happily using NSOperation subclasses again and I am using the NSURLSession API. [&#8230;] Note that I am triggering a KVO notification on isFinished as opposed to finished which is what the property name [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,800,31,275,30,476,71,901],"class_list":["post-13366","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-concurrency","tag-ios","tag-keyvalueobserving","tag-mac","tag-networking","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=13366"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13366\/revisions"}],"predecessor-version":[{"id":13367,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13366\/revisions\/13367"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=13366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=13366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=13366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}