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

标签 swift xcode xcode9 code-folding xcode10

<分区>

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

但在 Xcode 8 中,我可以通过 Editor >> Code Folding >> Fold 将代码折叠成 block (即单独的 if 语句),但在 Xcode 9 中,这会折叠整个方法。

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

最佳答案

更新 Xcode 10

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

  1. 一个新的代码折叠功能区,显示编辑器中的所有多行可折叠代码块
  2. 编辑器中折叠代码的新样式,允许您使用折叠代码编辑行
  3. 支持折叠花括号中的任何代码块
  4. 支持折叠功能区、结构化选择或
  5. 中的折叠代码块

Menubar ► Editor ► Code Folding ► Fold menu item

enter image description here

看看这个快照:

enter image description here


代码折叠在 Xcode 9 beta 1 中被禁用,根据 beta 发行说明,它现在可以在 Xcode 9 Beta5 中使用:Resolved in Xcode 9 beta 5 – IDE

方法如下:

  1. 按住键盘上的 (命令)按钮并将鼠标光标移动/悬停在任何(开始或结束)大括号上。它会自动高亮、遮挡区域。
  2. 保持(按住)(命令)按钮处于按下状态,然后单击突出显示的区域。它将启用带有 Fold 选项的快速菜单弹出窗口。
  3. 从菜单列表中选择Fold。它将折叠您的代码并显示 3 个点,折叠/覆盖整个 block 。
  4. 现在,要再次展开您的代码块,请松开 (命令)按钮并单击折叠 block 的 3 个点。

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

enter image description here


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

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


Xcode 菜单中的代码折叠选项:

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

这是引用快照:

enter image description here

来自 Xcode 快捷方式列表的相同选项:

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

enter image description here

关于swift - Xcode 9/10 中的代码折叠更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46387262/

相关文章:

arrays - "Cannot Subscript a value of type ' [字符串] ' with an index of type ' 字符串 ' "

iphone - 核心数据 - 保存电子邮件地址

ios - 将 UITableView 样式更改为 "Grouped"导致崩溃

xcode - Storyboard未在视觉上更新

Xcode 9 : Multiple Working Copies Git

ios - Gif用作分页加载器时,有时不显示在 ImageView 中

快速包管理器链接动态库

ios - 适用于 IOS 的 Flutter 应用程序,是否可以在不使用 Xcode 的情况下设置 IOS "Legacy Build System"?

C++ - 函数声明符后的预期函数体 - Xcode 9.0

ios - 动态添加部分到 UITableView,然后动态添加子单元格到特定部分。