PDA

View Full Version : Problems using variable as argument in startSpeakingString:




subsonix
Apr 19, 2008, 04:45 PM
Hi,

I have some problems with using a variable as argument with the startSpeakingString method. The variable is an integer and the expression looks like this:

[myObject startSpeakingString: @"%i", variable];

When I do like this I get a "too many arguments" error and if I put a parantes around the string and variable I get a "…makes pointer from integer without a cast" warning.

I have tried to add NSLog(@"%i", variable); and it works as expected.

Any Ideas what I might be doing wrong here?



BigJimSlade
Apr 19, 2008, 05:59 PM
Try:

[myObject startSpeakingString: [NSString stringWithFormat:@"%i", variable]];

startSpeakingString wants an NSString, and you were passing a static NSString and an int. To get the "printf" effect you're after, you need to use the factory methods NSString provides.

I.

subsonix
Apr 19, 2008, 07:43 PM
Yes thatīs it, now it works.

Thank you!