Xcode 9/10 中的代码折叠更改

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

Code Folding changes in Xcode 9/10

swiftxcodexcode9code-foldingxcode10

提问by joffd

I know code folding was missing in the early Beta's of Xcode9 and that it is available to fold entire methods with CMD click.

我知道在 Xcode9 的早期 Beta 版中缺少代码折叠,并且可以使用 CMD 单击折叠整个方法。

But in Xcode 8 i was able to fold code in blocks (i.e. individual if statements) via Editor >> Code Folding >> Foldbut in Xcode 9 this folds the entire method.

但是在 Xcode 8 中,我能够通过Editor >> Code Folding >> Fold 将代码折叠成块(即单个 if 语句),但在 Xcode 9 中这折叠了整个方法。

Is there a fix/setting i can change to restore the Xcode 8 functionality?

是否有修复/设置我可以更改以恢复 Xcode 8 功能?

采纳答案by Kaisp

It is stated in the release notes that it is not supported as of yet.

发行说明中指出,目前尚不支持它。

回答by Krunal

Updates in Xcode 10

Xcode 10 中的更新

Xcode 10 has increased support for code folding, including:

Xcode 10 增加了对代码折叠的支持,包括:

  1. A new code folding ribbon showing all of the multi-line foldable blocks of code in the editor
  2. A new style for folded code in the editor that allows you to edit lines with folded code
  3. Support for folding any block of code enclosed in curly braces
  4. Support for folding blocks of code from the folding ribbon, from structured selection, or from the
  1. 显示编辑器中所有多行可折叠代码块的新代码折叠功能区
  2. 编辑器中折叠代码的新样式,允许您编辑带有折叠代码的行
  3. 支持折叠花括号中的任何代码块
  4. 支持从折叠功能区、结构化选择或从

Menubar ? Editor ? Code Folding ? Fold menu item

菜单栏 ?编辑?代码折叠 ? 折叠菜单项

enter image description here

在此处输入图片说明

Look at this snapshot:

看看这个快照:

enter image description here

在此处输入图片说明



Code folding was disabled in Xcode 9 beta 1, which is working now, in Xcode 9 Beta5according to beta release note: Resolved in Xcode 9 beta 5 – IDE

代码折叠在 中被禁用Xcode 9 beta 1,现在正在运行,Xcode 9 Beta5根据测试版发布说明:已在 Xcode 9 beta 5 – IDE 中解决

Here is how:

方法如下:

  1. Press and hold ?(command) button in keyboard and move/hover mouse cursor on any (start or end) braces. It will automatically highlight, block area.
  2. Keep (hold) ?(command) button in pressed condition and click on highlighted area. It will enable quick menu popover window with Foldoption.
  3. Select Foldfrom menu list. It will fold your code and shows 3 dots, folding/covering entire block.
  4. Now, to again unfold your code block, release ?(command) button and click on 3 dots folding a block.
  1. 按住?键盘上的(命令)按钮并将鼠标光标移动/悬停在任何(开始或结束)大括号上。它会自动突出显示,阻止区域。
  2. 保持(按住)?(命令)按钮处于按下状态,然后单击突出显示的区域。它将启用带有Fold选项的快速菜单弹出窗口。
  3. Fold从菜单列表中选择。它将折叠您的代码并显示 3 个点,折叠/覆盖整个块。
  4. 现在,再次展开您的代码块,释放?(命令)按钮并单击折叠块的 3 个点。

For easy understanding, look at this snapshot:

为了便于理解,请看这张快照:

enter image description here

在此处输入图片说明


It's all keyboard short cuts are also working.


所有的键盘快捷键也都有效。

Fold                          ? ? ←      option + command + left arrow
Unfold                        ? ? →      option + command + right arrow
Unfold All                    ? U        option + U
Fold Methods & Functions      ? ? ↑      option + command + up arrow
Unfold Methods & Functions    ? ? ↓      option + command + down arrow
Fold Comment Blocks           ? ? ? ↑    control + shift + command + up
Unfold Comment Blocks         ? ? ? ↓    control + shift + command + down
Focus Follows Selection       ? ? ? F    control + option + command + F
Fold All                      ? ? ? ←    command + option + shift + left
Unfold All                    ? ? ? →    command + option + shift + left


Code folding options from Xcode Menu:


Xcode 菜单中的代码折叠选项

Menubar ? Editor ? Code Folding ? "Here is list of code folding options"

菜单栏 ?编辑?代码折叠 ? “这是代码折叠选项列表”

Here is ref snapshot:

这是参考快照:

enter image description here

在此处输入图片说明

Same options from Xcode Short-cut list:

来自 Xcode Short-cut list 的相同选项

Menubar ? Xcode ? Preferences ? Key Bindings ? "Here is list of code folding short-keys"

菜单栏 ?代码?喜好 ?键绑定?“这是代码折叠快捷键列表”

enter image description here

在此处输入图片说明

回答by vadian

You can fold individual ifstatements also in Xcode 9 however it folds the entire if - (else)expression.

您也可以if在 Xcode 9 中折叠单个语句,但它会折叠整个if - (else)表达式。

Put the cursor somewhere within the block and press ??←

将光标放在块内的某个位置并按 ??←

Unfolded:

展开:

enter image description here

在此处输入图片说明

Folded:

折叠:

enter image description here

在此处输入图片说明