• 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: NSDictionary valueForKey: and @ character at start of NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary valueForKey: and @ character at start of NSString


  • Subject: Re: NSDictionary valueForKey: and @ character at start of NSString
  • From: "Clark Cox" <email@hidden>
  • Date: Tue, 15 May 2007 07:45:00 -0700

On 5/15/07, Joe Goh <email@hidden> wrote:
On 5/15/07, Buddy Kurz <email@hidden> wrote:
> How about prepending some other character when the key is stored and
> removing it when reading the key to get the string
>
> NSString * myKey = [NSString stringWithFormat:@"-%@",userString];
>
> NSString * userString = [myKey stringFromIndex:1];

The problem with this approach is that its rather brittle, as I need
to remember to do this everytime I call NSDictionary valueForKey:.  If
I prepend the string with some character once I receive the input, and
only strip it out when I need to output it or manipulate it, its also
really brittle and unmaintainable as this will lead to sprinkling lots
of stringFromIndex: method calls all over the place.  I think this is
a rather unmaintainable approach in general and i'd much rather avoid
it.

Just put the transformation in a single place (class, method, function, whatever) and it'll be quite maintainable.

You should *always* be validating input from the user anyway (user
input cannot be implicitly trusted, and is, by definition,
unpredictable). Just add this transformation to the validation that
you're already doing (you are validating the user's input, right?).


On the main topic again though; will my category implementation as
described in my original email cause any problems with internal Cocoa
APIs or otherwise?

Eventually. For instance dictionaries are supposed to provide values for keys such as "@count". With your category, dictionaries will instead check to see if they contain a "count" key.

--
Clark S. Cox III
email@hidden
_______________________________________________

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


References: 
 >NSDictionary valueForKey: and @ character at start of NSString (From: "Joe Goh" <email@hidden>)
 >Re: NSDictionary valueForKey: and @ character at start of NSString (From: Sam Stigler <email@hidden>)
 >Re: NSDictionary valueForKey: and @ character at start of NSString (From: "Joe Goh" <email@hidden>)
 >Re: NSDictionary valueForKey: and @ character at start of NSString (From: Buddy Kurz <email@hidden>)
 >Re: NSDictionary valueForKey: and @ character at start of NSString (From: "Joe Goh" <email@hidden>)

  • Prev by Date: Re: Out-of-bounds error when removing entry from NSForm
  • Next by Date: Re: NSDictionary valueForKey: and @ character at start of NSString
  • Previous by thread: Re: NSDictionary valueForKey: and @ character at start of NSString
  • Next by thread: Re: NSDictionary valueForKey: and @ character at start of NSString
  • Index(es):
    • Date
    • Thread