Reputation: 7286
NSString* name = @"abc";
NSLog(name,nil);
who can tell me ,why add a nil? thank you very much.
Upvotes: 1
Views: 3738
Reputation: 10379
The signature of NSLog
is void NSLog (NSString *format, ...);
.
So the first argument is rather a format instead of a literal string. The second (and all following) arguments are the substitution values for the format string.
You should not replace the format string with the string you want to log. If your string contains format specifiers like %d
NSLog
will try to replace them but will fail to do so as you have not entered a substitution.
You should always log with NSLog(@"%@", string)
when you want to log string
.
Upvotes: 2
Reputation: 3054
That's not at all necessary, but NSLog
expects a const NSString:
NSLog(@"%@", name);
although, as long as there are no special flags like %p
, %d
, %s
, %@
, etc.
NSLog(myString);
will also work.
Upvotes: 0
Reputation: 4428
The correct way to print a NSString
using NSLog
is NSLog(@"%@", name);
.
Upvotes: 1