{"id":8144,"date":"2013-10-29T16:20:42","date_gmt":"2013-10-29T21:20:42","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=8144"},"modified":"2013-10-30T15:01:19","modified_gmt":"2013-10-30T20:01:19","slug":"key-value-observing-for-the-mainstream","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2013\/10\/29\/key-value-observing-for-the-mainstream\/","title":{"rendered":"Key-Value Observing for the Mainstream"},"content":{"rendered":"<p>I was going to write about the rare <a href=\"http:\/\/nshipster.com\/key-value-observing\/\">NSHipster article<\/a> that I <em>wouldn&rsquo;t<\/em> recommend, but <a href=\"http:\/\/ddeville.me\/2013\/10\/key-value-observing-for-the-mainstream\/\">Damien DeVille<\/a> already has:<\/p>\n<blockquote cite=\"http:\/\/ddeville.me\/2013\/10\/key-value-observing-for-the-mainstream\/\"><p>The truth is, in practice it is <em>very<\/em> important to <em>always<\/em> use the context to differentiate between observed objects and not rely on the key path. We are working with an object-oriented language and we should always accommodate for the case where a class might be subclassed or a super class expecting a behavior that your own class will prevent.<\/p>\n<p>[&#8230;]<\/p>\n<p>Or even worse, would you ever consider handling a signal for a memory error due to calling <code>free<\/code> on a freed piece of memory because you couldn&rsquo;t remember whether you previously retained this object and decided to release it anyway.<\/p>\n<p>No. Because this is madness.<\/p>\n<\/blockquote>\n<p>Update (2013-10-30): <a href=\"http:\/\/ddeville.me\/2013\/10\/a-note-about-kvo-dependent-keys\/\">Damien DeVille<\/a> has more on <code>+keyPathsForValuesAffectingValueForKey:<\/code>:<\/p>\n<blockquote cite=\"http:\/\/ddeville.me\/2013\/10\/a-note-about-kvo-dependent-keys\/\"><p>I hope this helped you understand how the key dependency KVO mechanism works. As I said in the previous post, KVO has very simple rules and is very powerful, as long as you follow the rules.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>I was going to write about the rare NSHipster article that I wouldn&rsquo;t recommend, but Damien DeVille already has: The truth is, in practice it is very important to always use the context to differentiate between observed objects and not rely on the key path. We are working with an object-oriented language and we should [&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,275,54,71],"class_list":["post-8144","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-keyvalueobserving","tag-objective-c","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8144","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=8144"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8144\/revisions"}],"predecessor-version":[{"id":8158,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8144\/revisions\/8158"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=8144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=8144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=8144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}