NSRunAlertPanel +格式字符串不是字符串文字(可能不安全)

the*_*end 4 objective-c nsstring

好的,所以我知道格式字符串不是字符串文字警告,但我不知道为什么它出现在NSRunAlertPanel上,定义是:

APPKIT_EXTERN NSInteger NSRunAlertPanel(NSString*title,NSString*msgFormat,NSString*defaultButton,NSString*alternateButton,NSString*otherButton,...)NS_FORMAT_FUNCTION(2,6);

报告错误时,我通常只在消息上传递error.localizedDescription,例如:

NSRunAlertPanel(@"error", err.localizedDescription, @"OK",nil,nil);
Run Code Online (Sandbox Code Playgroud)

但升级到xcode 5.1后,我开始收到此警告.

所以我尝试过这样的事情:

NSRunAlertPanel(@"error", [NSString stringWithFormat:@"%@", err.localizedDescription], @"OK", nil, nil);
Run Code Online (Sandbox Code Playgroud)

和它的情况一样.任何人有任何想法如何解决这个问题?

Mar*_*n R 8

msgFormat是消息格式字符串,应该是字符串文字.必要的参数后面添加为"变量参数列表" otherButton.例如

NSRunAlertPanel(@"error", @"%@", @"OK", nil, nil, err.localizedDescription);
           message format---^         arguments---^
Run Code Online (Sandbox Code Playgroud)