ios - Xcode Swift 代码折叠/折叠

标签 ios swift xcode macos code-folding

我知道我们可以使用“Shift + Alt + Cmd + Left”在 Xcode 中折叠/折叠 swift 代码,但谁能告诉我如何折叠/折叠仅功能不是属性或任何其他方式

默认的折叠方法可以完成这项工作,但实际上也对我们隐藏了非常重要的信息......

enter image description here

这就是我想要的!

enter image description here

最佳答案

更新 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

关于ios - Xcode Swift 代码折叠/折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40285997/

相关文章:

ios - Xcode - 可以在模拟器上运行应用程序但不能在设备上运行 - 错误 : Failed with exit code 1

ios - 如何在iOS(swift)项目中集成Paytm支付网关?无法创建 PGMerchantConfiguration 对象

ios - 在不使用 aws 的情况下为 RestKit 生成 S3 bucket url

ios - 无法设置 NSUserDefaults

ios - iOS 8 中未调用 CLLocationmanager updateLocations 委托(delegate)方法

ios - 我可以在 UITableview 中使用单元格标题而不是部分标题吗?

ios - 如何将底部和右侧边框添加到自定义 CollectionView

swift - willDisplayCell 第一行在 Swift 中不起作用

objective-c - iOS : Compiling Static Libraries

ios - iOS 可以在后台模式下捕捉视频吗?