NSObject *obj = @"A string or other object.";
NSLog([NSString stringWithFormat:@"%@",obj]);// 有警告
NSLog([NSString stringWithFormat:@"%@",obj],nil);// 解决方案
为何如此?
解答=>上面可以直接写成:
NSLog(@"A string or other object.");
//或者
NSObject *obj = @"A string or other object.";
NSLog(@"%@",obj);
//没有必要再调用 NSString的 stringWithFormat: 方法
===============================================================
注:警告信息:“Format string is not a string literal (potentially insecure)”说明NSLog要求的参数为字面量,不可为NSString* 类型,如:
NSString* s=...;
NSLog(s) //警告
//-------------------------
NSLog([NSString stringWithFormat...]);//依旧警告