2011-12-04 27 views
0

私はそれをどのように行うのです文字列/数字を文字列に追加するにはどうすればよいですか?

objectForKey:@"level + STRING/NUMBER"

のように機能私は、文字列「レベル」に変数currentLevelを追加したい

-(void) generateLevelFromPlist:(int)currentLevel{ 
    NSString *mainPath = [[NSBundle mainBundle] bundlePath]; 
    itemPositionPlistLocation = [mainPath stringByAppendingPathComponent:@"levelconfig.plist"]; 
    NSDictionary * itemPositions = [[NSDictionary alloc] initWithContentsOfFile:itemPositionPlistLocation]; 
    NSNumber *xVal = [[[[itemPositions objectForKey:@"level + STRING/NUMBER"]objectForKey:@"hexposition"]objectForKey:@"hexagon1"]objectForKey:@"xVal"]; 
    int generatedXVal = [xVal integerValue]; 
    NSLog(@"%d", generatedXVal); 
    NSLog(@"%@", itemPositionPlistLocation); 



    } 

がありますか?

答えて

7

これを実行する方法はたくさんあります。この場合、最も簡単である:

myString = [NSString stringWithFormat:@"level + %d", currentLevel]

それとも

myString = [NSString stringWithFormat:@"%@ %d", initialString, currentLevel]

あなたはまたvalueForKeyPathを使用して検討するかもしれない。むしろobjectForKeyよりも何度も。 ([x valueForKeyPath:@"a.b.c"][[[x objectForKey:@"a"] objectForKey:@"b"] objectForKey:@"c"]に似ています)

+0

恐ろしいです!あなたにすっごくありがとう!ちなみに、私が実際に望んでいたのは、 'myString = [NSString stringWithFormat:@"レベル%d "、currentLevel]'がなくても... :) –

関連する問題