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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4594961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:03:48  来源:igfitidea点击:

How to clear console programmatically in Xcode?

iphoneobjective-cxcodedebugging

提问by NSExplorer

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 语句用于调试。每次我运行我的项目时,我都想从一个新的控制台屏幕开始。是否有任何命令可以嵌入我的代码中可以做到这一点?

采纳答案by stackr

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

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

回答by Ashwani

When in the console(Debug mode) use

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

Command + k 

to clear the console.

清除控制台。

回答by Tertium

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 中一样 :)

回答by Mark

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 窗口中谈论控制台,则“运行”菜单中有一个“清除控制台”选项。在“调试”首选项选项卡中还有一个“自动清除调试控制台”复选框。我指的是 Xcode 3.2.x

回答by Joshua Nozzi

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 impossiblebut it's ridiculously inconvenient.

简而言之:我认为这并非不可能,但它非常不方便。

回答by Aidan

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;
}

回答by Dinesh619

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

command + control + options + R 清除 xcode 中的控制台