【发布时间】:2011-06-03 10:58:29
【问题描述】:
我的代码中有一堆用于调试的 NSLog 语句。每次我运行我的项目时,我都想从一个新的控制台屏幕开始。我可以在我的代码中嵌入任何可以做到这一点的命令吗?
【问题讨论】:
标签: iphone objective-c xcode debugging
我的代码中有一堆用于调试的 NSLog 语句。每次我运行我的项目时,我都想从一个新的控制台屏幕开始。我可以在我的代码中嵌入任何可以做到这一点的命令吗?
【问题讨论】:
标签: iphone objective-c xcode debugging
我查看了所有答案,并且有一些替代方案,但我认为最终答案是:你不能(截至 2021 年 6 月)。
我使用的唯一选择是:添加断点。当执行到达断点时,单击 Ctr-K。继续执行。
【讨论】:
在控制台(调试模式)时,使用:
Xcode > Debug > Debug Workflow > Clear Console
键盘快捷键:Command ⌘+K
【讨论】:
也许您可以使用 Xcode 首选项中的“自动清除调试控制台”设置...
不知道这是否回答了你的问题?
【讨论】:
print("any value", terminator: Array(repeating: "\n", count: 100).joined())
我认为你唯一能做的就是
for(int i= 0; i < 100; i++)
NSLog(@" ");
就像在旧的 MS-DOS 中一样 :)
【讨论】:
puts(" ");
正如 stackr 所提到的,XCode Preferences 中的“Auto Clear Debug Console”设置将执行此操作。在代码中完成:
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;
}
【讨论】:
command + control + options + R 清除xcode中的控制台
【讨论】:
调试器控制台/运行日志基本上是来自您的应用程序的重定向“将其记录到控制台”命令。 “清除”在一般意义上没有任何意义,因为消息通常只是被分流到某个地方(如文件)。您的应用程序必须了解其调试环境,并能够告诉该环境清除它正在记录的任何内容。
简而言之:我想这不是不可能,但它非常不方便。
【讨论】:
如果您在 Xcode 窗口中谈论控制台,“运行”菜单中有一个“清除控制台”选项。在“调试”首选项选项卡中还有一个“自动清除调试控制台”复选框。我指的是 Xcode 3.2.x
【讨论】: