Where is my NSLog output?
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?
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 ⌘⇧C on your keyboard
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.
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);
Moved from comment
Are you sure that line with NSLog
is executed? Try to insert NSLog
right after autorelease pool allocation in main.m
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
.
精彩评论