{"id":1798,"date":"2008-10-22T21:14:26","date_gmt":"2008-10-23T01:14:26","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=1798"},"modified":"2008-10-22T21:14:28","modified_gmt":"2008-10-23T01:14:28","slug":"key-value-observing-done-right","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2008\/10\/22\/key-value-observing-done-right\/","title":{"rendered":"Key-Value Observing Done Right"},"content":{"rendered":"<p><a href=\"http:\/\/www.mikeash.com\/?page=pyblog\/key-value-observing-done-right.html\">Mike Ash<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.mikeash.com\/?page=pyblog\/key-value-observing-done-right.html\">\n<p>It&rsquo;s too bad that such a powerful tool is so broken. Especially since Apple is starting a trend of omitting traditional NSNotification and delegate callbacks in new APIs, instead simply supporting KVO. A perfect example of this is NSOperation: the only way to get notified when an NSOperation finishes is by using KVO to watch its <code>isFinished<\/code> property.<\/p><\/blockquote>\n<p>I hope those are mistakes and not part of a trend. In any case, Ash has done what I was planning to do the first time I couldn&rsquo;t avoid using KVO: write an adapter that hides the madness behind a notification center interface. It&rsquo;s simple and clean:<\/p>\n<blockquote cite=\"http:\/\/www.mikeash.com\/?page=pyblog\/key-value-observing-done-right.html\">\n<p>It takes advantage of one pointer that can be guaranteed to be unique: the &lsquo;self&rsquo; pointer. Instead of registering the target object for a notification, it creates a unique helper object for each notification and registers that. The helper then receives the notification and bounces it back to the original observer. <\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Mike Ash: It&rsquo;s too bad that such a powerful tool is so broken. Especially since Apple is starting a trend of omitting traditional NSNotification and delegate callbacks in new APIs, instead simply supporting KVO. A perfect example of this is NSOperation: the only way to get notified when an NSOperation finishes is by using KVO [&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":[],"class_list":["post-1798","post","type-post","status-publish","format-standard","hentry","category-programming-category"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/1798","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=1798"}],"version-history":[{"count":0,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/1798\/revisions"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=1798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=1798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=1798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}