Reputation: 3172
I am new to iOS programming.
I am getting an "Incompatible integer to pointer conversion sending 'int' to parameter of type 'NSString *'"
error when I try and run the following code:
- (IBAction)oneToSix {
int rNumber = arc4random() % 6;
[result setImage:[UIImage imageNamed: rNumber]];
}
Upvotes: 3
Views: 5011
Reputation: 52788
You need to convert the int
to a NSString
before sending it to the imageNamed
method. This is because imageNamed
takes a NSString
as the argument and not an int
. Try this:
- (IBAction)oneToSix {
int rNumber = arc4random() % 6;
[result setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d", rNumber]]];
}
More info here: UIImage Class Reference.
Upvotes: 8
Reputation: 48398
The problem is that imageNamed:
takes an NSString
as input, not an int
. To fix this, just convert the int
into an NSString
by
[NSString stringWithFormat:@"%d",rNumber]
Upvotes: 4