Re: Dynamic menu building
Re: Dynamic menu building
- Subject: Re: Dynamic menu building
- From: April Gendill <email@hidden>
- Date: Fri, 15 Aug 2003 12:00:01 -0700
On Friday, August 15, 2003, at 11:40 AM, j o a r wrote:
On den 15 augusti 2003, at 20:12:33PM, April Gendill wrote:
If you have your data structure made up of arrays and dictionaries
that look like this:
<array>
<dict>
<item>
<key> MY_TITLE_KEY</key>
<value>"a title"</value>
</item>
<item>
<key> MY_TITLE_KEY</key>
<value>"a title"</value>
<key>MY_SUBMENU_KEY</key>
<value>YES</value>
<key>MY_ITEMS_KEY</key>
<value>
<array>
// A similar structure as this one, nested
</array>
</value>
</item>
</dict>
</array>
I don't read XML very well, but what I understand says this is about
what I'm doing. there is some extra info in the dictionaries but
basically for this part of the process the name of the item and a
value for it being a submenu is all that gets read.
It's actually not really XML, just a fake XML-like notation to
illustrate what the data structure could look like. You said that
you're going to fetch some data of disc and build a menu structure
representing that data, so I assumed that you would use something like
this.
If you haven't already made plans for how to do this, may I suggest
that you take a look in the documentation, and the list archives, for
the topic of "property list serialization". It's very easy to store /
re-store an object graph based of property list objects (in this case
most likely just collection objects and strings).
Let's say you have an array of strings:
NSArray *arr = [NSArray arrayWithObjects: @"1", @"2", @"3", nil];
You can make string of this array sutiable for storing in a file like
this:
NSString *strRep = [arr description];
And also turn that string back into an array like this:
NSArray *arr2 = [strRep propertyList];
Easy!
I see here that I can gather the data globally or locally either way
as long as I have the correct data and know the keys, I can begin a
loop based on what ever identifier I need to use in order to get a
loop going.
Inside the loop I extract a submenu, initialize it with a static
variable, give it a name based on the data, add any items to it that
need adding, then stick it on the master menu. Next time through the
loop I start with the next dictionary of items, and it does not
matter that the variable name is the same because the loop will not
overwrite it's previous itteration, it will simply add the new
information.
Also make sure to note that this method is _recursive_, ie. it calls
itself. This is the key to being able to traverse a data structure of
known format, but unknown size.
ok then I suppose I'm not so terribly far off then and given another
few weeks i'll actually get it to work. (i'm still struggling with
getting a data structure that I like, that is quick to step through and
that I can keep organized in my own head so that the program will work)
My last real concern about this then is only, which is faster and more
efficent? using a model object to hold the menu or stepping through the
dictionaries, and building the menu in the same method that will return
it?
j o a r
_______________________________________________
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.