I have the following code snippet in my Xcode:
NSString *digit [[sender titlelabel] text]; NSLog([digit]);
I tried to build the application and am getting the following warning message for the line NSLog([digit]);
Warning: Format not a string literal and no format arguments
Can you advise me how I can resolve this warning message? What does the message actually mean?
In the Thread Programming Guide, NSLog() is listed as being 'generally considered to be thread-safe'.
NSLog : NSLog adds a timestamp and identifier to the output, whereas print will not; NSLog statements appear in both the device's console and debugger's console whereas print only appears in the debugger console.
NSLog outputs messages to the Apple System Log facility or to the Console app (usually prefixed with the time and the process id).
NSLog() output on the simulator does indeed show up in the Console Mac OS X application. Go to All Messages and then filter based on your app name to get rid of the fluff, and run again. You'll see it in your output if the NSLog code is actually being hit during the execution of your program.
Try this piece of code:
NSString *digit = [[sender titlelabel] text]; NSLog(@"%@", digit);
The message means that you have incorrect syntax for using the digit
variable. If you're not sending it any message - you don't need any brackets.
Use NSLog()
like this:
NSLog(@"The code runs through here!");
Or like this - with placeholders:
float aFloat = 5.34245; NSLog(@"This is my float: %f \n\nAnd here again: %.2f", aFloat, aFloat);
In NSLog()
you can use it like + (id)stringWithFormat:(NSString *)format, ...
float aFloat = 5.34245; NSString *aString = [NSString stringWithFormat:@"This is my float: %f \n\nAnd here again: %.2f", aFloat, aFloat];
You can add other placeholders, too:
float aFloat = 5.34245; int aInteger = 3; NSString *aString = @"A string"; NSLog(@"This is my float: %f \n\nAnd here is my integer: %i \n\nAnd finally my string: %@", aFloat, aInteger, aString);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With