Reputation: 12820
I have a function
-(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);
}
where I want to add the variable currentLevel to the string "level" as in objectForKey:@"level + STRING/NUMBER"
How do I do that ?
Upvotes: 0
Views: 137
Reputation: 57168
There are lots of ways to do this. The easiest in this case is:
myString = [NSString stringWithFormat:@"level + %d", currentLevel]
Or
myString = [NSString stringWithFormat:@"%@ %d", initialString, currentLevel]
You might also consider using valueForKeyPath: rather than objectForKey over and over. ([x valueForKeyPath:@"a.b.c"]
is similar to [[[x objectForKey:@"a"] objectForKey:@"b"] objectForKey:@"c"]
)
Upvotes: 7