You could swizzle the objectForKey: and setObject:forKey: methods with your own that just lowercase the passed in string and then call the actual methods with the new key.

Dave

Sent from my iPod

On Mar 16, 2009, at 8:02 AM, Roland King <r...@rols.org> wrote:

Any good ideas for doing a key-case-insensitive NSDictionary of NSString to NSString? I have some HTTP headers I want to stick in a dictionary and look up later. HTTP headers have case-insensitive keys.

I could upper, or lowercase the key before putting it in the NSMutableDictionary, but that means I lose the original case of the key (I probably shouldn't care but I hate throwing away information), and any user of my class has to know to upper or lowercase the key before looking it up, or else I don't expose the dictionary at all and just give lookup methods which hide the details. That's a shame, I wanted the user to have access too all the keys if they wanted it and wanted to just make the NSDictionary available as a property.

I could make a case-insensitive string, but subclassing NSString wasn't in my plans for Monday evening, or Tuesday and the user still has to make the same NSCaseInsensitiveString() object to look up the key.

I could make a case-insensitive version of NSMutableDictionary which ... oh that's worse, forget I even said that.

I think I'm going to lower-case on insert and tell the user the NSDictionary of headers has lower-case keys but .. is there something obvious I missed? _______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/davedelong%40me.com

This email sent to davedel...@me.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to