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

Re: Searching dictionaries


  • Subject: Re: Searching dictionaries
  • From: April Gendill <email@hidden>
  • Date: Fri, 10 Oct 2003 23:22:39 -0700

On Friday, October 10, 2003, at 10:44 PM, James McConnell wrote:

On 10/10/03 10:37 PM, "April Gendill" <email@hidden> wrote:

I have a data structure. The root is a dictionary which contains
string items and other dictionaries (possibly nested). I tried
enumerating the dictionary but I cannot remove an item or other wise
use it because the enumerator only provides either a string or
dictionary object.
I tried [theDict allKeysForObject:theObject];

"theObject" is a selected item from a table. Am I not understanding
what "The Object" is suppose to be? Because when I NSLog(@"%@",[theDict
allKeysForObject:theObject]); The array is empty even though I can log
the object and the dictionary and they both show an object by the same
name. Basically I cannot step through a nested dictionary and remove
either a string or dictionary because I guess I do not understand how
to reference the data.

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

First, are you using NSDictionary or NSMutableDictionary? I'm not trying to
belittle your intelligence or anything, but I've made that mistake, so you
might want to check and make sure you're using NSMutableDictionary or
NSMutableArray to guarantee that you can delete/add/modify objects within
the dictionary/array.


its a global mutable dictionary

Other than that, just off the top of my head, I would create some kind of
recursive method that steps through a dictionary. Call it on your root
dictionary, then every time you encounter an object in your dictionary, test
it and see if it's another dictionary. If it is, call the recursive method
again on that one, and so on and so forth until you've gone through each
one. If you have many nested dictionaries (dictionaries inside dictionaries
inside dictionaries), you might want to take a look at your data structure.
But since you didn't say how deep it went, that's more of a heads-up, as I
don't know what your structure looks like.


Creating a recursive method would not be difficult for me if I have the slightest Idea how to get the key names from an enumerator or how to find an object in a nested dictionary.

Wish I could post some code for you, but it's late and I'm heading to bed,
but that should get you started. Hope that helps, happy coding!

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

  • Follow-Ups:
    • Re: Searching dictionaries
      • From: Just van Rossum <email@hidden>
References: 
 >Re: Searching dictionaries (From: James McConnell <email@hidden>)

  • Prev by Date: Re: Searching dictionaries
  • Next by Date: How does NSTableView decide to tell an NSCell to highlight on and after mouseDown?
  • Previous by thread: Re: Searching dictionaries
  • Next by thread: Re: Searching dictionaries
  • Index(es):
    • Date
    • Thread