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

Re: NSDictionary question


  • Subject: Re: NSDictionary question
  • From: Jonathan Jackel <email@hidden>
  • Date: Fri, 4 Jul 2003 09:58:46 -0400

If you can't get at your data efficiently, maybe the problem is your data structure, not your algorithm.

Seems like you could use a tree structure for your data. That way you can go up AND down the hierarchy. The cost is that you'll need to tell each object who its parent is and who its children are. Then you just ask the object you are interested in who its parent is.

You also might consider putting your "root" key in dictionary you are querying, like this:

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

Jonathan


On Thursday, July 3, 2003, at 10:53 PM, Koen van der Drift wrote:

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.
_______________________________________________
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.

References: 
 >NSDictionary question (From: Koen van der Drift <email@hidden>)

  • Prev by Date: Re: Wildcard in NSString
  • Next by Date: Re: awakeFromNib and windowWillLoad : basic question
  • Previous by thread: NSDictionary question
  • Next by thread: Algorithm for fitting a string in a given width
  • Index(es):
    • Date
    • Thread