0

I've come across a rather weird issue with stringWithFormat:. I create a string and assign it to an alert panel.

For some reason though, Xcode says that the format string isn't a string literal even though it is? Can anyone shed some light?

enter image description here

Header declaration:

APPKIT_EXTERN void NSBeginCriticalAlertSheet(NSString *title, NSString *defaultButton, NSString *alternateButton, NSString *otherButton, NSWindow *docWindow, id modalDelegate, SEL didEndSelector, SEL didDismissSelector, void *contextInfo, NSString *msgFormat, ...) NS_FORMAT_FUNCTION(10,11);

Edit: Looking at the header declaration, it came to me. I was missing a nil after the msgFormat variable. Xcode's warning was confusing though - it should have been missing sentinel in function call instead.

Pripyat
  • 2,937
  • 2
  • 35
  • 69

2 Answers2

0

Use this

 NSString *localizedStr=[NSString stringWithFormat:@"bla bla %@ bla bla",_dev.name];
    NSString *_warning = NSLocalizedString(localizedStr);

    /*code for alert sheet
Ishu
  • 12,797
  • 5
  • 35
  • 51
0

I think the problem is that you try to pass a NSString with a paramater inside a method that does the same. So the NSBeginCriticalAlertSheet is actually looking for another parameter.

If you put it in another NSString stringWithFormat: it takes the literal string instead of trying to parse it.

So in your NSBeginCriticalAlertSheet: _warning should be replaced with

[NSString stringWithFormat:@"%@", _warning]

Also see warning-format-not-a-string-literal-and-no-format-arguments for more information.

Community
  • 1
  • 1
Roland Keesom
  • 8,180
  • 5
  • 45
  • 52