25

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!

sch
  • 27,436
  • 3
  • 68
  • 83
Borut Tomazin
  • 8,041
  • 11
  • 78
  • 91

3 Answers3

43

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!";);
sch
  • 27,436
  • 3
  • 68
  • 83
5

%@ 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
Vaibhav Sharma
  • 1,123
  • 10
  • 22
2

Remove that semi colon after #define and use %@ and it will work.

Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115