开发者

Can somebody help me out with plists?

开发者 https://www.devze.com 2023-01-12 14:21 出处:网络
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.

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.


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];
        } 
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号