20

I've just started out learning iOS development. I'm using some NSLog statements in my code but they don't appear to be output anywhere. My application is using the debug configuration and I'm running my application in the iPhone simulator from within Xcode. I've checked both the Xcode console (under the Run menu) and also Console.app on my Mac, but there's nothing.

What could be the problem?

4

5 に答える 5

20

Make sure you have your Console activated. To do that, you can:

  • Go to View > Debug Area > Activate Console (From your Menu Bar)
  • Or press ⌘</kbd>⇧</kbd>C on your keyboard
于 2014-05-17T21:25:37.940 に答える
7

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.

于 2011-03-06T22:27:56.830 に答える
4

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);
于 2011-03-07T17:37:48.863 に答える
3

Moved from comment

Are you sure that line with NSLog is executed? Try to insert NSLog right after autorelease pool allocation in main.m

于 2011-03-07T17:28:16.873 に答える
1

Really weird. Just for the sake of experiment: try to redirect the NSLog output to some file like this:

freopen ("/out","w", stderr);
NSLog(@"1234567890");

If there is an output, then there is something wrong with your stderr.

于 2011-03-06T23:53:22.937 に答える