• 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
NSDictionary question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSDictionary question


  • Subject: NSDictionary question
  • From: Koen van der Drift <email@hidden>
  • Date: Thu, 3 Jul 2003 22:53:45 -0400

Hi,

I have an NSDictionary with the following structure:

<dict>
<key>A</key>
<dict>
<key>code</key>
<string>Aap</string>
...
</dict>

<key>B</key>
<dict>
<key>code</key>
<string>Banaan</string>
...
</dict>
...
</dict>

Now at one point in my code I need to convert a string that is made up of only the values that correspond to the key 'code' (Aap, Banaan, ...) to their 'root key' (A, B,...).

What I do now is the following:

1. use a keyEnumerator to iterate over all keys of the NSDictionary.
2. get the object (a dict) from each key and then get the value of the key 'code'
3. store both the 'value' and the 'key' in a new NSMutableDictionary using setObject:forKey

4. scan the original string that needs to be converted
5. for each word ('value') look up the corresponding key
6. append the 'key' to a new NSMutableString.

Now I have a converted string.


I have a feeling this can be done much easier (less complicated), but I haven't been able to figure out how.

Any suggstions/improvements?


thanks,


- Koen.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSDictionary question
      • From: Jonathan Jackel <email@hidden>
  • Prev by Date: OmniAppKit's Licky Inspectors - Help!
  • Next by Date: Algorithm for fitting a string in a given width
  • Previous by thread: OmniAppKit's Licky Inspectors - Help!
  • Next by thread: Re: NSDictionary question
  • Index(es):
    • Date
    • Thread