0

I'm working on an iOS app and I need the user to be able select a subject of a certain report through a decision tree (using the UITableView to advance trough the available options). I'm trying to find a good way of order all the available options, there are about 5 layers and 10+ items for some of the layers.

  • Cabinets
    • Wooden
      • Black
        • shiny
        • not shiny
          • etc
    • Brown
      • etc
    • White
      • etc
  • Steel
    • etc
  • Fabric
    • etc

Can anyone maybe advice a certain variable type to do this with? I've thought about using a NSMutableArray and populating it with pointers to other arrays etc, but I figured I'd end up with a whole bunch of pointers where only in the end there are actually NSStrings returned (if that makes any sense).

1 Answer 1

1

My suggestion is using plists to make your life easier. Plists can be read easily into NSDictionary and NSArray objects; you can also persist NSArray and NSDictionary easily into plists, if you need it. This is true if the plist content are types that support the NSCoding protocol (which seems to be the case for your example data).

The main advantage in your case is that you could use Xcode plist editor to create your plist file (which is just an XML file) and then read it into memory and access its content as Obj-C objects, without worrying about having to create yourself all the NSArrays to hold the pointers.

I've thought about using a NSMutableArray and populating it with pointers to other arrays etc, but I figured I'd end up with a whole bunch of pointers where only in the end there are actually NSStrings returned (if that makes any sense)...

This is correct and it is a way you can go. You could build your arrays manually, or use the plist editor, as I mentioned above.

Otherwise you could look for some specialized data structure implementation apt to represent a decision tree. Have also a look at CHDataStructures, which is a collection of data structures in Obj-C.

2
  • 1
    It's worth taking a look at valueForKeyPath: method which can simplify working with many Plists/NSArray/NSDictionary. Jan 20, 2012 at 14:55
  • Great stuff! That has been very useful! The plist is loading perfectly and an I'm populating an NSArray.
    – Chris
    Jan 21, 2012 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.