Xcode 中的多行注释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1513380/
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-09 03:10:28  来源:igfitidea点击:

Multi-line comments in Xcode

xcode

提问by BigJoke

Is there a way to comment various lines at the same time in Xcode IDE? Selecting which lines to comment, then clicking somewhere et voilá.. the /* ... */ characters wrapping the code.

有没有办法在 Xcode IDE 中同时注释多行?选择要注释的行,然后单击某处等等等等.. /* ... */ 包装代码的字符。

Thank you.

谢谢你。

回答by Georg Sch?lly

Command+ Shift+ 7

Command+ Shift+7

or

或者

Command+ /

Command+ /

This inserts //in front of every selected line.

这将插入//到每个选定行的前面。

回答by Carl

Xcode Version 6.1

Xcode 6.1 版

Shortcuts:

快捷方式:

To Comment: Select the code to be comment, ? + /

评论:选择要评论的代码,? + /

To uncomment: Select the code an press ? + /

取消注释:选择代码并按 ? + /

Also see taskbar Editor>Structure "(un)Comment Selection" as user 2137640 pointed out.

另请参阅用户 2137640 指出的任务栏编辑器>结构“(un)Comment Selection”。

回答by KZcoding

The answer is actually very simple if you want to comment a continuous sequence of lines. Select the consecutive lines, then simply press ? /.

如果要注释连续的行序列,答案实际上非常简单。选择连续的行,然后只需按? /

I have no idea how to comment multiple non-consecutive lines. Maybe somebody else can help with this, if it is even possible (I doubt it.)

我不知道如何评论多个不连续的行。也许其他人可以帮助解决这个问题,如果有可能的话(我对此表示怀疑。)

回答by dmeister

There is such a function in the menu. Try: Edit->Insert Text Macro->C->Comment Section. It will create a (multi-line) comment around the currently selected text.

菜单里有这样的功能。尝试:Edit->Insert Text Macro->C->Comment Section。它将围绕当前选定的文本创建一个(多行)注释。

However, using the menu is probably often slower than manually inserting the comments. But, you can also bind a key to the menu item via the preferences key binding settings.

但是,使用菜单可能通常比手动插入注释慢。但是,您也可以通过首选项键绑定设置将键绑定到菜单项。

回答by rinkesh

For single line Comment use ?+/
For multiline Comment you need to install CComent plugin

对于单行注释使用 ?+/
对于多行注释,您需要安装CComent plugin

to install plugin manager use alcatraz

安装插件管理器使用alcatraz

回答by guest

Got it! You have to un-indent the lines so the comments are the first character on the line, not a tab or whitespace - then pressing CMD+/ works. Just tried it in XCode 5.1.1, works like a charm.

知道了!您必须取消缩进行,以便注释是该行的第一个字符,而不是制表符或空格 - 然后按 CMD+/ 即可。刚刚在 XCode 5.1.1 中尝试过,效果很好。

回答by Edwin Ikechukwu Okonkwo

This worked !

这奏效了!

Higlight the desired lines then press Command + /

突出显示所需的行,然后按Command + /

The same rule goes for uncommenting.

同样的规则适用于取消注释。

回答by kvra13

in Xcode 7.x

在 Xcode 7.x 中

Shortcuts:

快捷方式:

To Comment: Select the code to be comment, ? + /

评论:选择要评论的代码,? + /

To uncomment: Select the code an press ? + /

取消注释:选择代码并按 ? + /

回答by Adeel

For xcode 8 ->
sudo /usr/libexec/xpccachectl
restart your computer

对于 xcode 8 ->
sudo /usr/libexec/xpccachectl
重新启动您的计算机