• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: case-insensitive NSDictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: case-insensitive NSDictionary


  • Subject: Re: case-insensitive NSDictionary
  • From: Dave DeLong <email@hidden>
  • Date: Mon, 16 Mar 2009 08:05:23 -0600

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 <email@hidden> 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 (email@hidden)

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:
This email sent to email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: case-insensitive NSDictionary
      • From: Bill Bumgarner <email@hidden>
    • Re: case-insensitive NSDictionary
      • From: Dave DeLong <email@hidden>
References: 
 >case-insensitive NSDictionary (From: Roland King <email@hidden>)

  • Prev by Date: case-insensitive NSDictionary
  • Next by Date: Re: Messages between Threads
  • Previous by thread: case-insensitive NSDictionary
  • Next by thread: Re: case-insensitive NSDictionary
  • Index(es):
    • Date
    • Thread