The following code gets me the result I want in the NSLog but there must be an easier way to do this? I’m also getting a ‘format string is not a string literal’ error, which still builds okay.
NSString *levelstring1 = @"Level ";
NSString *levelstring2 = [NSString stringWithFormat:@"%d", levelscore];
NSString *levelstring3 = @" (";
NSString *levelstring4 = [NSString stringWithFormat:@"%d", xpscore];
NSString *levelstring5 = @"/";
NSString *levelstring6 = [NSString stringWithFormat:@"%d", (levelscore*(levelscore+1)*100)];
NSString *levelstring7 = @")";
NSString *levelstringfinal = [[[[[[levelstring1 stringByAppendingFormat:levelstring2]stringByAppendingFormat:levelstring3]stringByAppendingFormat:levelstring4]stringByAppendingFormat:levelstring5]stringByAppendingFormat:levelstring6]stringByAppendingFormat:levelstring7];
NSLog(@"Level is %@",levelstringfinal);
The end result looks something like this: Level 1 (50/100).
You can combine them into something like:
The warning you’re getting is because the compiler can’t check a variable’s content, whereas with a string literal it can match placeholders and variables for some degree of consistency.
(Even if you had to build the string in pieces, the last line would be better using
stringByAppendingStringrather thanstringByAppendingFormatbecause those are no longer format specifiers.)