Re: Searching dictionaries
Re: Searching dictionaries
- Subject: Re: Searching dictionaries
- From: James McConnell <email@hidden>
- Date: Sat, 11 Oct 2003 00:44:07 -0500
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.
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.
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.