Re: NSDictionary valueForKey: and @ character at start of NSString
Re: NSDictionary valueForKey: and @ character at start of NSString
- Subject: Re: NSDictionary valueForKey: and @ character at start of NSString
- From: "Joe Goh" <email@hidden>
- Date: Tue, 15 May 2007 22:45:28 +0800
On 5/15/07, Sam Stigler <email@hidden> wrote:
I'm not sure about your category implementation, but I still think you
should really think seriously about implementing a basic hash method,
perhaps even something like what Buddy has suggested, is probably the best,
easiest way to achieve the result you want.Not only is NSValueTransformer
a Cocoa standard API, so you don't have to worry about any potentially bad
side effects, but also it is bindings capable
The problem with using the method Buddy has suggested is mainly code
maintability. I would hate to sprinkle bits and pieces of the
workaround all over my code base whenever I need to access a value in
an NSDictionary.
The bindings bit is also not useful to me as my user input is not from
an NSTextField or in fact any UI control - its from a hardware device
(for my app's case, a Treo smartphone), and the user's input is
retrieved from a seperate conduit application.
To reiterate, it still seems unnecessary to me to implement a category for
this.
Actually, the category method is really short, so its not much effort at all.
@implementation NSDictionary (valueForKey)
- (id) valueForKey: (NSString*)key
{
return [self objectForKey:key];
}
@end
In addition, it actually works - avoiding the exception thrown by my
app previously. After running through my own tests for awhile, its
currently shipping production code.
More importantly, it seems pretty clean and maintainable as I can add
more code confidently to the codebase without constantly having to
worry, "Have I added the @ workaround to this bit of NSString code
too?". With this one category, I have worked around this issue
throughout the entire codebase.
Does anyone *know* why Apple has decided to add the extra
functionality to NSDictionary to handle strings with @ characters at
the start seperately? Is it for some internal Cocoa use or some
remnant from NeXT? Is my category method safe for production use?
Thanks!
Joe Goh
FunkeeMonk Technology
http://www.funkeemonk.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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