开发者

plist read failures

I have some problem converting my data from an plist to objects.

The plist has following structure

plist read failures

I read the file with the following code

-(void)readAnimationsFromPlist
{
    NSDictionary *dict;
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Animationen" ofType:@"plist"];
    dict = [[NSDictionary alloc] initWithContentsOfFile:path];
    CCLOG(@"%@", [dict description]);
    for (NSDictionary *items in dict)
    {
        Animation *animation = [[Animation alloc] init];
        animation.name = items.description;
        CCLOG(@"%@", items);
        animation.delay = [items valueForKey:@"delay"]; //(1)
        animation.phases = [items valueForKey:@"phases"];
        CCLOG(@"Animation %@ mit %i frames eingelesen", items.description, animation.phases.count);
        [animationen setObject:animation forKey:animation.name];
        [animation release]; //(2)
    }
    [dict release];
    CCLOG(@"%i animationen eingelesen", [animationen count]);
 }

My problem is now, that no data get read in line marked with (1) throws always the following exception.

Terminating app due to uncaught exception 'NSUnknownKey开发者_JAVA技巧Exception', reason: '[<NSCFString 0x55d3ba0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key delay.'

I found some info about this message but nothing helpful.

  • It is no binding problem (no IB in use)
  • When i use objectForKey there is another error

When i look into inspector window when debugging it shows me that items is of Type NSCFString with value 'Hauptgewinn' but it should be an dictionary. I tried to cast it explicit to an NSDictionary but there is nothing changing.

What could i do to solve this problem?

On position (2) must i release that there or can i delete this line?


//2 is correct.

-(void)readAnimationsFromPlist
{
    NSDictionary *dict;
    NSString *path = [[NSBundle mainBundle] pathForResource:@"untitled" ofType:@"plist"];
    dict = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSLog(@"Dictionary is: %@", dict);
    for(id key in dict)
    {
        Animation *animation = [[Animation alloc] init];
        animation.name = key;
        CCLOG(@"%@", key);
        animation.delay = [[dict valueForKey:key] valueForKey:@"delay"]; //(1)
        animation.phases = [[dict valueForKey:key] valueForKey:@"phases"];
        CCLOG(@"Animation %@ mit %i frames eingelesen", items.description, animation.phases.count);
        [animationen setObject:animation forKey:animation.name];
        [animation release]; //(2)

    }
    [dict release];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜