Can't find one under
Xcode ▶ Preferences/Text Editing ▶ "Code Folding Ribbon" box.
Collapse/expand the code block by clicking the -/+ icons on the gutter. Press ⌃ ⌥ + / ⌃ ⌥ - to collapse/expand all the code in your file recursively.
Keep (hold) ⌘ (command) button in pressed condition and click on highlighted area. It will enable quick menu popover window with Fold option. Select Fold from menu list. It will fold your code and shows 3 dots, folding/covering entire block.
Updates in Xcode 10:
Xcode 10 has increased support for code folding, including:
Menubar ► Editor ► Code Folding ► Fold menu item
Look at this snapshot:
Xcode 9
Code folding was disabled in Xcode 9 beta 1, which is working now, in Xcode 9 Beta5 according to beta release note: Resolved in Xcode 9 beta 5 – IDE
Here is how:
Fold
option.Fold
from menu list. It will fold your code and shows 3 dots, folding/covering entire block.For easy understanding, look at this snapshot:
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:
Menubar ▶ Editor ▶ Code Folding ▶ "Here is list of code folding options"
Here is ref snapshot:
Same options from Xcode Short-cut list:
Menubar ▶ Xcode ▶ Preferences ▶ Key Bindings ▶ "Here is list of code folding short-keys"
Concurring with comment by @strangetimes, I submitted to Apple Bug Reporter the following, in the new SUGGESTION format. Please feel free to pile on to Apple with your own:
35237858 : Code Folding in Xcode 9.1 Only does Entire Functions/Methods
UPDATE, A YEAR LATER…
This is fixed in Xcode 10. Code folding is back. Thanks to all those who piled on to the bug report or whatever.
The new, improved code folding in Xcode 9 or 9.1 seems to only work on an entire function or method. (I'm working in Objective-C today.) This is not very useful. You know, functions or methods are only one curly bracket deep. It is easy to eyeball them. Where I need code folding is for long control flow blocks – if, else, switch, do, while, or just loose blocks. Please bring it back so I can use code folding as it worked in Xcode 8.
The ribbon thing, although I thought it was good, others didn't – I can live without it. But code folding needs to work on all curly-bracket code blocks please.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With