0
votes

I am having some trouble formatting an NSString

So i have and NSString and an Int

I want to use them to set an Image in a IUImage View, here is my code

headOnString = @"test";
slideNumber = 0;
NSLog(@"%@%i.png",headOnString, slideNumber);
photoDisplay.image = [UIImage imageNamed:(@"%@%i.png", headOnString, slideNumber)];

the goal is for this is to read [UIImage imageNamed:@"test0.png"];

im getting an "expression result unused for the "headOnString" string and an "incompatible pointer conversion sending int to NSString"

I always have trouble with string formatting. Any suggestions would be greatly appreciated. Thanks.

1

1 Answers

3
votes

use this:

photoDisplay.image = [UIImage imageNamed: [NSString stringWithFormat:@"%@%i.png", headOnString, slideNumber]];

and take care that the format fits the type of the variables, you can easily crash by using wrong format for your variables.