<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2010-05-28-leopard-collection-classes.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-05-28-leopard-collection-classes.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sat, 06 Jun 2026 19:22:31 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>mikeash - 2010-06-23 03:50:41</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-05-28-leopard-collection-classes.html#comments</link><description>While that answers the question of why they haven't (and probably can't) fix it, it doesn't answer the question of why they built it that way in the first place.</description><guid isPermaLink="true">92a100f815e2ddaa24a5b34583da1b38</guid><pubDate>Wed, 23 Jun 2010 03:50:41 GMT</pubDate></item><item><title>Kyle Sluder - 2010-06-23 03:31:00</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-05-28-leopard-collection-classes.html#comments</link><description>I imagine the main reason for making -setObject:forKey: always copy the key irrespective of the options passed to the CF constructor was compatibility with existing code that passed mutable strings as dictionary keys, relying on them being copied. Of course, as you say, the opportunity for making that breaking change has certainly not increased since.</description><guid isPermaLink="true">5f89e5ddc7a0539eef886c3c89a21462</guid><pubDate>Wed, 23 Jun 2010 03:31:00 GMT</pubDate></item><item><title>mikeash - 2010-05-29 23:02:45</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-05-28-leopard-collection-classes.html#comments</link><description>&lt;b&gt;Harvey:&lt;/b&gt; I haven't bothered. I know what the behavior is now, and don't think it would be worth the time to file a bug.
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Mike Abdullah:&lt;/b&gt; That's amusing. I don't know how comfortable I'd be relying on this, but on the other hand it probably couldn't be changed without breaking tons of code now.</description><guid isPermaLink="true">a8f08d31571ad8669b67fa7801bfea14</guid><pubDate>Sat, 29 May 2010 23:02:45 GMT</pubDate></item><item><title>Mike Abdullah - 2010-05-29 11:54:12</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-05-28-leopard-collection-classes.html#comments</link><description>My understanding is that it is the NSDictionary methods which provide the copying behaviour. Keys are copied then passed on to CoreFoundation to deal with.
&lt;br /&gt;
&lt;br /&gt;This is true regardless of how the dictionary was created. So if you allocate an NSDictionary, but then set keys using CoreFoundation, they will be retained not copied. I have a convenience method (ab)using this:
&lt;br /&gt;
&lt;br /&gt;- (void)setObject:(id)anObject forKey:(id)aKey copyKeyFirst:(BOOL)copyKey;
&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (copyKey)
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[self setObject:anObject forKey:aKey];
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CFDictionarySetValue((CFMutableDictionaryRef)self, aKey, anObject);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&lt;br /&gt;}</description><guid isPermaLink="true">fbc8a0b91f1b001bc8cad5b0eeefb349</guid><pubDate>Sat, 29 May 2010 11:54:12 GMT</pubDate></item><item><title>Harvey - 2010-05-29 07:54:45</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-05-28-leopard-collection-classes.html#comments</link><description>Mike: Have you tried filing a bug on the bridging docs?</description><guid isPermaLink="true">cd23cc700985c81862bdf96d802d289e</guid><pubDate>Sat, 29 May 2010 07:54:45 GMT</pubDate></item><item><title>mikeash - 2010-05-28 18:41:47</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-05-28-leopard-collection-classes.html#comments</link><description>&lt;b&gt;Christopher Lloyd:&lt;/b&gt; Stuff with the same name existed, but is so different that I don't consider it to be the same API at all. They were like CF collections but without any of the conveniences they offered. Now they're actually useful.
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Charles Parnot:&lt;/b&gt; Thanks for pointing out those convenience methods, I missed them because they're in a category. Regarding the radar, I believe the documentation is contradictory here. You're correct that the method is documented as saying the key is copied, but CFDictionary is documented as calling your callback, and the bridging docs don't state who wins.</description><guid isPermaLink="true">01da1de5038159312c63ef3fcc785316</guid><pubDate>Fri, 28 May 2010 18:41:47 GMT</pubDate></item><item><title>Charles Parnot - 2010-05-28 18:15:45</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-05-28-leopard-collection-classes.html#comments</link><description>Great overview, thanks very much!
&lt;br /&gt;
&lt;br /&gt;One thing maybe was not explicit in the text about NSPointerArray: it also has the class methods `+pointerArrayWithStrongObjects` and `+ pointerArrayWithWeakObjects`. Just pointing it out in case somebody is intimidated by the NSPointerFunctions stuff.
&lt;br /&gt;
&lt;br /&gt;About #4350677, on the other hand, the documentation for 'setObject:forKey:' says "..The key is copied..", so it seems they just stick to what the docs say ;-)
&lt;br /&gt;</description><guid isPermaLink="true">64957ca86f643983b981096f362e2c2f</guid><pubDate>Fri, 28 May 2010 18:15:45 GMT</pubDate></item><item><title>Christopher Lloyd - 2010-05-28 17:41:37</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-05-28-leopard-collection-classes.html#comments</link><description>NSHashTable and NSMapTable have been around since 10.0 and before, they were just C structs prior to 10.5. I assume the upgrade to a class and the new options were to make them work sanely with the GC. Disappointingly they aren't in iPhoneOS, I find myself using NSMapTable quite a lot. </description><guid isPermaLink="true">64716d0732abda91ba25268a09b43970</guid><pubDate>Fri, 28 May 2010 17:41:37 GMT</pubDate></item></channel></rss>
