I have a string constant defined like this:
#define kMyString @"This is my string text!";
Somewhere in the code I would like to print-out this piece of code with NSLog like that:
NSLog(@"This is it: %@",kMyString);
But get a build error: Expected expression
.
I have already looked at the Apple's Format Specifiers but could not figured it out.
Can someone please explain it to me how to do this?
Thanks!
There is no format specifier to print boolean type using NSLog. One way to print boolean value is to convert it to a string. Another way to print boolean value is to cast it to integer, achieving a binary output (1=yes, 0=no).
A static, plain-text Unicode string object which you use when you need reference semantics or other Foundation-specific behavior.
15.4. 4.2 The Print Command With Objective-C Also, an additional command has been added, print-object or po for short, which is meant to print the description of an object. However, this command may only work with certain Objective-C libraries that have a particular hook function, _NSPrintForDebugger , defined.
You should remove ;
from the definition of kMyString
:
#define kMyString @"This is my string text!"
The way you did it is equivalent to:
NSLog(@"This is it: %@", @"This is my string text!";);
%@
is for objects. BOOL
is not an object.
On the bases of data type %@
changes as follows
For Strings you use %@
For int you use %i
For float you use %f
For double you use %lf
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