I'm testing on OS X. I've got a source file that's heavy with preprocessor macros and tests. I'm trying to collapse the code so I can determine why a particular symbol is not being defined.
According to Apple's Folding and Unfolding Source Code, I should be able to do it through the focus ribbon. That's not working - there is no ribbon, and the editor does not respond to requests from the menu.
According to Stack Overflow's Enable code-folding by default (and others like How to collapse all methods in XCode?), I can use hot keys to do it. That's not working either - the editor appears to ignore them too.
I don't have #pragma marks
or #regions
, so Can you set code regions in Xcode? does not apply.
How do I force Xcode to provide code folding?
.
(see below)
.
√
Once completed, the shortcuts for folding and unfolding within Xcode should work.
Updates in Xcode 10
Xcode 10 has increased support for code folding, including:
Menubar ► Editor ► Code Folding ► Fold menu item
Look at this snapshot:
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:
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