How to clear console programmatically in Xcode?

早过忘川 提交于 2020-03-17 04:28:26

问题


I have a bunch of NSLog statements in my code which I use for debugging. Every time I run my Project I'd like to start from a fresh console screen. Is there any command I can embed in my code which can do this?


回答1:


Maybe you could use the "Auto Clear Debug Console" setting in the XCode Preferences.. Don't know if this answers your question?




回答2:


When in the console(Debug mode) use

Command + k 

to clear the console.




回答3:


I think the only thing you can is

for(int i= 0; i < 100; i++) 
NSLog(@" ");

just like in good old MS-DOS :)




回答4:


If you are talking about the console in the Xcode window there is a "Clear Console" option in the "Run" menu. There is also, in the "Debugging" Preferences tab an "Auto Clear Debug Console" checkbox. I am referring Xcode 3.2.x




回答5:


The debugger console / run log are basically a redirected "log this to the console" command from your app. "Clearing" it means nothing in the general sense, since the messages are usually just shunted somewhere (like a file). Your application would have to know about its debugging environment and be able to tell that environment to clear whatever it's logging to.

In short: I suppose it's not impossible but it's ridiculously inconvenient.




回答6:


As mentioned by stackr, the "Auto Clear Debug Console" setting in the XCode Preferences will do this. To do it in code:

bool ClearXCodeDebuggerConsole()
{
    NSString *const scriptText = @"\
tell application \"System Events\"\n\
set currentapp to the name of the current application\n\
end tell\n\
tell application \"Xcode\" to activate\n\
tell application \"System Events\"\n\
keystroke \"r\" using {command down, control down, option down}\n\
end tell\n\
tell application currentapp to activate\n\
return true";

    NSAppleScript *script = [[[NSAppleScript alloc] initWithSource:scriptText] autorelease];
    [scriptText release];
    NSDictionary *dictError = nil;
    NSAppleEventDescriptor *result = [script executeAndReturnError:&dictError];

    if (!result) return false;
    if ([result booleanValue] != YES) return false;
    return true;
}



回答7:


command + control + options + R clears the console in xcode



来源:https://stackoverflow.com/questions/4594961/how-to-clear-console-programmatically-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!