在XCode中 点 Run->Console可以查看NSLog的记录。
NSLog(@"log: %@ ", myString);
NSLog(@"log: %f ", myFloat);
NSLog(@"log: %i ", myInt);
NSLog() 寫到文件
- (void) redirectConsoleLogToDocumentFolder {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *logPath = [documentsDirectory stringByAppendingPathComponent:@"console_log.txt"];
freopen([logPath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
}
// 用得時候
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[self redirectConsoleLogToDocumentFolder];
}
然後在Xcode Organizer裡邊取出來