これが私の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];
このコードの問題は、2番目のforループを実行し、高さと幅の両方をゼロに戻すことです。
何か案が?またはどのように私はそれを適切な方法で行うのですか?