How do I append a string/number to a string ?

前端 未结 1 729
Happy的楠姐
Happy的楠姐 2021-01-28 20:59

I have a function

 -(void) generateLevelFromPlist:(int)currentLevel{
    NSString *mainPath = [[NSBundle mainBundle] bundlePath];
    itemPositionPlistLocation          


        
相关标签:
1条回答
  • 2021-01-28 21:01

    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"])

    0 讨论(0)
提交回复
热议问题