Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR data argument not used by format string on mySLComposerSheet

I'm a bit confused at why I'm getting the ERROR 'data argument not used by format string'

Has anybody else got this or fixed this in Xcode 4.5 for iOS6?

- (IBAction)facebookPost:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
    mySLComposerSheet = [[SLComposeViewController alloc] init];
    mySLComposerSheet = [SLComposeViewController  composeViewControllerForServiceType:SLServiceTypeFacebook];

    [mySLComposerSheet setInitialText:[NSString stringWithFormat:@"I'm listening to Boilerroom Recordings via the Boilerroom iPhone Application",mySLComposerSheet.serviceType]];

    [mySLComposerSheet addImage:[UIImage imageNamed:@"BOILERROOM_LOGO_250x250.png"]];
    [self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
    NSLog(@"dfsdf");
    switch (result) {
        case SLComposeViewControllerResultCancelled:
            break;
        case SLComposeViewControllerResultDone:
            break;
        default:
            break;
    }
}];

}
like image 413
Nathan Cleary Avatar asked Sep 27 '12 12:09

Nathan Cleary


1 Answers

The error you have is quite self-explainatory: as you use stringWithFormat, you are supposed to provide some formatting placeholder in your format string (like %@ as a placeholder for a object, %d for integers, %f as a placeholder of a float, etc, like in all printf-like methods).

But you don't use any. So the argument mySLComposerSheet.serviceType you put after the format string is not used by the format string (no placeholder) and is useless here. Thus the error saying that "the data argument (namely mySLComposerSheet.serviceType) is not used by the format string".


So the solution depending on what you intend to do:

  • If you really want to insert the serviceType somewhere in your string, simply add a %@ (as serviceType is an NSString*, thus an object) placeholder in your format string, at the position you what the value of mySLComposerSheet.serviceType to be inserted. For example:

    [mySLComposerSheet setInitialText:[NSString stringWithFormat:@"I'm listening to Boilerroom Recordings via the Boilerroom iPhone Application and want to share it using %@ !",mySLComposerSheet.serviceType]];
    
  • But I guess that in fact you don't want to insert the serviceType value anywhere in your initialText string (I wonder why you added this argument at the first place). In that case, you can simply remove this useless additional argument of your call to stringWithFormat:. Or better, because at that point your stringWithFormat call won't have any format placeholder like %@ at all, this is totally useless to use stringWithFormat anyway, so simply use the string literal directly!

    [mySLComposerSheet setInitialText:@"I'm listening to Boilerroom Recordings via the Boilerroom iPhone Application"];
    
like image 110
AliSoftware Avatar answered Sep 23 '22 22:09

AliSoftware