如何在Xcode中以编程方式清除控制台?

时间:2022-04-20 23:05:25

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?

我的代码中有很多NSLog语句用于调试。每次运行我的项目时,我都希望从一个新的控制台屏幕开始。有什么命令可以嵌入到我的代码中来实现这一点吗?

7 个解决方案

#1


8  

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

也许您可以使用XCode首选项中的“自动清除调试控制台”设置。不知道这是否能回答你的问题?

#2


47  

When in the console(Debug mode) use

在控制台(调试模式)使用

Command + k 

to clear the console.

控制台。

#3


19  

I think the only thing you can is

我想你唯一能做的就是

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

just like in good old MS-DOS :)

就像老的MS-DOS:)

#4


10  

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

如果您正在讨论Xcode窗口中的控制台,那么在“Run”菜单中有一个“Clear console”选项。在“调试”选项卡中还有一个“自动清除调试控制台”复选框。我指的是Xcode 3.2.x

#5


3  

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.

调试器控制台/运行日志基本上是从应用程序中重定向到控制台的“log this to The console”命令。“清除”在一般意义上没有任何意义,因为消息通常只是在某个地方被分流(比如文件)。您的应用程序必须了解它的调试环境,并能够告诉该环境以清除它所记录的内容。

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

简而言之:我认为这不是不可能的,但却非常不方便。

#6


1  

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

正如stackr所提到的,XCode首选项中的“自动清除调试控制台”将会这样做。用代码完成:

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


-5  

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

命令+控件+选项+ R清除xcode中的控制台

#1


8  

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

也许您可以使用XCode首选项中的“自动清除调试控制台”设置。不知道这是否能回答你的问题?

#2


47  

When in the console(Debug mode) use

在控制台(调试模式)使用

Command + k 

to clear the console.

控制台。

#3


19  

I think the only thing you can is

我想你唯一能做的就是

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

just like in good old MS-DOS :)

就像老的MS-DOS:)

#4


10  

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

如果您正在讨论Xcode窗口中的控制台,那么在“Run”菜单中有一个“Clear console”选项。在“调试”选项卡中还有一个“自动清除调试控制台”复选框。我指的是Xcode 3.2.x

#5


3  

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.

调试器控制台/运行日志基本上是从应用程序中重定向到控制台的“log this to The console”命令。“清除”在一般意义上没有任何意义,因为消息通常只是在某个地方被分流(比如文件)。您的应用程序必须了解它的调试环境,并能够告诉该环境以清除它所记录的内容。

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

简而言之:我认为这不是不可能的,但却非常不方便。

#6


1  

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

正如stackr所提到的,XCode首选项中的“自动清除调试控制台”将会这样做。用代码完成:

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


-5  

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

命令+控件+选项+ R清除xcode中的控制台