自升级到最新的Xcode 3.2.1和Snow Leopard以来,我一直在收到警告
"格式不是字符串文字,没有格式参数"
来自以下代码:
NSError *error = nil;
if (![self.managedObjectContext save:&error])
{
NSLog([NSString stringWithFormat:@"%@ %@, %@",
errorMsgFormat,
error,
[error userInfo]]);
}
Run Code Online (Sandbox Code Playgroud)
如果errorMsgFormat
是NSString
格式说明符(例如"print me like this: %@"
:),上面的NSLog
调用有什么问题?什么是修复它的建议方法,以便不生成警告?
我在NSLog行中收到警告
Format string is not a string literal(potentially insecure)
Run Code Online (Sandbox Code Playgroud)
从以下代码
NSMutableString *MarqueeMessage = [[NSMutableString alloc]init];
[MarqueeMessage appendString:@"Abc"];
NSString *immutableString = MarqueeMessage;
NSLog(immutableString);
Run Code Online (Sandbox Code Playgroud)
我可以问为什么在将这行改为以下代码后,警告消失了?
NSLog(immutableString,nil);
Run Code Online (Sandbox Code Playgroud) 为什么我的NSMutableString
潜在不安全?我搜索了这个但找不到任何东西.
int hour = [number intValue] / 3600;
NSMutableString *time = [[NSMutableString alloc] initWithString:@""];
if (hour < 9) {
[time appendFormat:@"0"];
[time appendFormat:[NSMutableString stringWithFormat:@"%d:", hour]];
}
Run Code Online (Sandbox Code Playgroud)
它出什么问题了?这是我第一次看到这个.