iPhone Tree Data Structure

646 views Asked by At

This is mostly a Data Struct question but the implementation is on the iphone.

I have a file on disk that i'm loading and parsing on each startup.

The file is in the form of XML so i'm using NSXMLParser to parse it.

The Data is build as a tree and looks like this:

1 General
 1.2 Work
  1.2.1 Employee
  1.2.2 Manager
 1.3 Home
  1.3.1 Wife
  1.3.2 Kids

I want to show this on a UITableView with Navigation control. So General will appear in first screen, when i click it, I will push a new tableview and will see Work and Home When i Click Work i will push another view with Employee and Manager, etc..

What is the best way to achieve this mission ? What data structure should I use from the iPhone frameworks? Any tips how to do it correctly ? Any apple example of something similar ? Thanks!

1

There are 1 answers

2
Max On BEST ANSWER

You should use array of arrays of arrays of arrays... it depends on the depth of your tree. So in your parser you should use NSMutableArray. Or, if you want to store some keyed non-homogeneous data, then you should use NSMutableDictionary, where the key is probably NSString and value is NSMutableArray.