Problems using variable as argument in startSpeakingString:

Discussion in 'Mac Programming' started by subsonix, Apr 19, 2008.

  1. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #1
    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?
     
  2. BigJimSlade macrumors member

    Joined:
    Dec 16, 2005
    #2
    Try:

    Code:
    [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.
     
  3. subsonix thread starter macrumors 68040

    Joined:
    Feb 2, 2008

Share This Page