This how i construct my PLIST.
<dict>
<key>level1</key>
<dict>
<key>formation</key>
<dict>
<key>height</key>
<integer>34</integer>
<key>width</key>
<integer>12</integer>
</dict>
</dict>
</dict>
level>formation>data
This is the example code i used, but it didnt work.
//init loading from PLIST here, and then associate value.
NSString *pathString=[NSString stringWithFormat:@"%@Levels",targetWorld];
NSString *path = [[NSBundle mainBundle] pathForResource:pathString ofType:@"plist"];
NSString *levelNameNumber = [[NSString alloc] initWithFormat:targetLevel];
NSDictionary *levelsList = [[NSDictionary alloc] initWithContentsOfFile:path];
NSDictionary *level = [levelsList objectForKey:levelNameNumber];
NSEnumerator *levelFormations = [level objectEnumerator];
for( NSDictionary *worldSize in levelFormations )
{
worldWidth = [[worldSize objectForKey:@"width"] intValue];
worldHeight = [[worldSize objectForKey:@"height"] intValue];
NSLog(@"height is %d",worldHeight);
NSLog(@"width is %d",worldWidth);
}
[levelNameNumber release];
[levelsList release];
problem with this code is that it runs a second for loop and returns both the height and width to ZERO.
Any idea? or how do i do it the proper way?
Since you’re using an object from levelsList, and you’re releasing levelsList at the end, the level object you got from the dictionary will also be released. You either need to not release levelsList, retain level, or preferably start using ARC.