views:

33

answers:

1

Hi all,

I have a little problem with plists. I don't know how to read data from my plist and in general how to structure it correctly. Here is how it should look like:

  • Root
    • product 1
      • type 1
        • string 1
        • string 2
      • typ2 2
        • string 1
        • string 2
    • product 2
      • type 1
        • string 1
        • string 2
      • typ2 2
        • string 1
        • string 2

The strings are paths to images and I want to use these images in my app. But I'm not quite sure how to access the strings and if root, product and type should be dictionaries or arrays.

I hope someone can help me.

+1  A: 

root should be a dictionary whose keys are products and whose values are dictionaries with keys type and values array of strings. You can read the plist in the following way:

    NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:@"Table 310-16" ofType:@"plist"];
NSDictionary *products = [[NSDictionary alloc] initWithContentsOfFile:plistPath];

for (id product in products) {
        NSDictionary *types = [product  objectForKey:products];
        for (id type in types) {
             NSArray *strings = [types objectForKey:type];
        } 
} 
ennuikiller
Thanx!!! Works fine.
Crazer