这就是我构建我的 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>
水平>形成>数据
这是我使用的示例代码,但它没有工作。
//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];
这段代码的问题是它运行了第二个 for 循环并将高度和宽度都返回为零。
任何想法?或者我该如何以正确的方式做到这一点?