Xcode控制台,以编程方式清除屏幕

5

我对Xcode和编程都比较新手。

在我的代码中,如何从Xcode显示控制台并清除屏幕?

我知道可以通过Xcode首选项完成,但我想以编程的方式实现。

2个回答

3
这对我来说可行-如果您希望Xcode保持在应用程序的顶部,请省略最后一个“activate”部分:
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;
}

对于AppKit(OS X)非常准确,但不幸的是,对于iOS UIKit则不然。具体来说,从AppKit文档派生的iOS库#import <Foundation/Foundation.h> @import Foundation不支持NSAppleScript和NSAppleEventDescriptor。https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSAppleScript_Class/ - eGanges

1

您可以通过按下 Shift + Command + R 来显示控制台窗口。您可以通过按下 Control + Option + Command + R 来清除控制台窗口。这两个选项都可以从“运行”菜单中使用。


谢谢你在这里提供帮助,但是这个并没有在编程上对我有所帮助。 - eGanges

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接