<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Key Value Observing Improvements</title>
	<atom:link href="http://shiftedbits.org/2008/07/24/key-value-observing-improvements/feed/" rel="self" type="application/rss+xml" />
	<link>http://shiftedbits.org/2008/07/24/key-value-observing-improvements/</link>
	<description>Bits were made to be shifted</description>
	<pubDate>Wed, 07 Jan 2009 16:45:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Devin Lane</title>
		<link>http://shiftedbits.org/2008/07/24/key-value-observing-improvements/#comment-205</link>
		<dc:creator>Devin Lane</dc:creator>
		<pubDate>Wed, 03 Sep 2008 05:42:43 +0000</pubDate>
		<guid isPermaLink="false">http://shiftedbits.org/?p=23#comment-205</guid>
		<description>Christian:

You raise some good points about the context argument. I've released an update (see http://shiftedbits.org/2008/09/03/key-value-observing-improvements-v12/) that includes the selector in determining the uniqueness of an observation. This allows a class and a subclass to observe a single property on a single object with different selectors. This has several advantages over the static NSString* method:

1. No need to declare said strings.
2. No need to check in your -observeValueForKeyPath method if the context is your context.
3. No need to call super.</description>
		<content:encoded><![CDATA[<p>Christian:</p>
<p>You raise some good points about the context argument. I&#8217;ve released an update (see <a href="http://shiftedbits.org/2008/09/03/key-value-observing-improvements-v12/" rel="nofollow">http://shiftedbits.org/2008/09/03/key-value-observing-improvements-v12/</a>) that includes the selector in determining the uniqueness of an observation. This allows a class and a subclass to observe a single property on a single object with different selectors. This has several advantages over the static NSString* method:</p>
<p>1. No need to declare said strings.<br />
2. No need to check in your -observeValueForKeyPath method if the context is your context.<br />
3. No need to call super.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christiaan</title>
		<link>http://shiftedbits.org/2008/07/24/key-value-observing-improvements/#comment-204</link>
		<dc:creator>Christiaan</dc:creator>
		<pubDate>Tue, 19 Aug 2008 16:25:20 +0000</pubDate>
		<guid isPermaLink="false">http://shiftedbits.org/?p=23#comment-204</guid>
		<description>The context argument is NOT optional in practice, the fact that the API allows it is no reason you should pass NULL. You should ALWAYS use a context, and I'm quoting several well known Apple engineers. You can google for detailed reasons. The main reason is that otherwise you can NEVER know if the observation message is meant for you (there can be any number of observers for the same key/object pair). Moreover, it should always be a unique pointer, and 'self' is far from unique (given the context). A simple solution is to use a static NSString * with a unique name.</description>
		<content:encoded><![CDATA[<p>The context argument is NOT optional in practice, the fact that the API allows it is no reason you should pass NULL. You should ALWAYS use a context, and I&#8217;m quoting several well known Apple engineers. You can google for detailed reasons. The main reason is that otherwise you can NEVER know if the observation message is meant for you (there can be any number of observers for the same key/object pair). Moreover, it should always be a unique pointer, and &#8217;self&#8217; is far from unique (given the context). A simple solution is to use a static NSString * with a unique name.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Devin Lane</title>
		<link>http://shiftedbits.org/2008/07/24/key-value-observing-improvements/#comment-200</link>
		<dc:creator>Devin Lane</dc:creator>
		<pubDate>Thu, 24 Jul 2008 18:15:48 +0000</pubDate>
		<guid isPermaLink="false">http://shiftedbits.org/?p=23#comment-200</guid>
		<description>Steve:

This is already a category on NSObject. I'm not sure what you mean.

How would you determine if the context argument is a string? It's not as though you can call methods on it.

The context argument is most certainly optional, in the sense that anything that can be interpreted as a pointer (an integer of the right size basically) can be passed. I pass NULL almost all the time. However, setting the context argument to self could be useful for determining if a call to super is needed.</description>
		<content:encoded><![CDATA[<p>Steve:</p>
<p>This is already a category on NSObject. I&#8217;m not sure what you mean.</p>
<p>How would you determine if the context argument is a string? It&#8217;s not as though you can call methods on it.</p>
<p>The context argument is most certainly optional, in the sense that anything that can be interpreted as a pointer (an integer of the right size basically) can be passed. I pass NULL almost all the time. However, setting the context argument to self could be useful for determining if a call to super is needed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://shiftedbits.org/2008/07/24/key-value-observing-improvements/#comment-199</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Thu, 24 Jul 2008 16:45:04 +0000</pubDate>
		<guid isPermaLink="false">http://shiftedbits.org/?p=23#comment-199</guid>
		<description>I have written code that uses the key and creates a selector "keyChanged" and if its implemented, calls that. If that is not implemented, it has other fallbacks to try.
You COULD make this a category on NSObject and never write another observeValueForKeyPath method. You could also see if the context argument is a string and use it help your code decide what to do.

Also, keep in mind that the context argument is NOT optional and MUST always be provided and if it is not what you expect, then call [super observeValueForKeyPath....]</description>
		<content:encoded><![CDATA[<p>I have written code that uses the key and creates a selector &#8220;keyChanged&#8221; and if its implemented, calls that. If that is not implemented, it has other fallbacks to try.<br />
You COULD make this a category on NSObject and never write another observeValueForKeyPath method. You could also see if the context argument is a string and use it help your code decide what to do.</p>
<p>Also, keep in mind that the context argument is NOT optional and MUST always be provided and if it is not what you expect, then call [super observeValueForKeyPath....]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.217 seconds -->
