Re: Getting the content-type in a HTTP response
Re: Getting the content-type in a HTTP response
- Subject: Re: Getting the content-type in a HTTP response
- From: Andy Lee <email@hidden>
- Date: Fri, 25 Jan 2008 20:29:29 -0500
I would create a utility method, perhaps a category method on
NSDictionary something like objectForCaseInsensitiveKey: that does the
linear search. Yes, it hides that fact that you're doing a linear
search in what most people would assume is a constant-time lookup, but
unless and until those extra cycles really matter it's not worth more
engineering than that IMO. And yes, other programmers will have to
remember to use this case-insensitive method rather than the natural
objectForKey:, but I think this is a reasonable compromise.
--Andy
On Jan 25, 2008, at 6:57 PM, Dave Carrigan wrote:
On Jan 25, 2008, at 3:35 PM, Bill Garrison wrote:
I guess you'd have to do something similar with every HTTP header
key.
Which I think reinforces my assertion that Apple really was
shortsighted in designing the API, since returning a case-sensitive
dictionary is pretty much useless for the task at hand, since it
seems I have to do a linear search of the dictionary in order to
find any item in it, which is useless and stupid.
If apple had been even remotely close to thinking, they would have
at least downcased all the headers before inserting them into the
dictionary, but it seems like that would have been too visionary.
So my next question is if it's possible to override NSDictionary's
comparison operator to be case insensitive (a la STL's maps) or if I
should just create a new dictionary that copies the old dictionary
with downcased keys. The former would be more bulletproof since it
wouldn't require other programmers to remember to downcase all their
dictionary lookups.
--
Dave Carrigan
email@hidden
Seattle, WA, USA
_______________________________________________
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