How can you write log files in Objective C?
If I'm doing mass operations inside objective C, and a lot happens in the console... I cannot see it all happen in windows.
Instead of adding the argument ">>WriteLog.log"
what would the pr开发者_运维知识库oper way to log the console inside of Objective C?
NSLog
is the normal way to log to the console in Objective-C
You can use it like:
NSLog(@"My log string");
or
NSLog(@"%@", someStringObject);
Agreed with James, NSLog is the first method I've ever used with Obj-C to log.
To expand on James' the NSLog requires a string object as it's first argument, with optional referenced variables as following arguments.
IE:
int someInteger = 5;
NSString *someString = @"STRING";
double someDouble = 2.34;
NSLog(@"This is an INT: %i, while this is a string: %@, while this is a double: %.2f",someInteger,someString,someDouble);
// Output: 2010-08-30 11:45:25.400 StackOverflow[380:a0f] This is an INT: 5, while this is a string: STRING, while this is a double: 2.34
To see where %@, %i, %.2f come from, study string format specifiers.
精彩评论