Is there a way to tell XCode fold methods/functions by default when opening a file?
7 Answers
If you want to fold / unfold specific blocks of code, since Xcode 7, you have to enable that.
Go to Xcode > Preferences > Text Editing > and check 'Code folding ribbon'.
(No idea why they disabled this useful feature by default.)

- 1,609
- 2
- 12
- 17
-
4That's awfully annoying. I just re-enabled it - thanks for the tip! – Greg Brown Oct 05 '15 at 16:05
-
8Cannot find it in xCode 9 (beta) – Ofir Malachi Jul 03 '17 at 08:13
-
@OfirMalachi that is because is has not been implemented! – Alex Bollbach Jul 05 '17 at 16:15
Not sure if this is an OS change, or an Xcode change, but on Lion with Xcode 4, some of these commands cited by Griffo are performed with the Option modifier (the ⌥ key), not control. I've made some changes to reflect this:
Fold ⌥⌘← option+command+left
Unfold ⌥⌘→ option+command+right
Unfold All ⌥U option+U
Fold Methods/Functions ⌥⌘↑ option+command+up
Unfold Methods/Functions ⌥⌘↓ option+command+down
Sorry to necro a thread, but I thought this was worthwhile to revise.

- 1,351
- 1
- 14
- 20
-
10On OS X, Xcode 4.3, the fold all/unfold all changed to shift-option-command-left/right – Cbas Aug 08 '12 at 21:13
-
1In Xcode 5.1 fold/unfold Methods/Functions by Shift-Command-Option-Left/Right too – M Zubair Shamshad Sep 23 '14 at 13:11
Updates in Xcode 10:
Xcode 10 has increased support for code folding, including:
- A new code folding ribbon showing all of the multi-line foldable blocks of code in the editor
- A new style for folded code in the editor that allows you to edit lines with folded code
- Support for folding any block of code enclosed in curly braces
- Support for folding blocks of code from the folding ribbon, from structured selection, or from the
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:
- Press and hold
⌘
(command) button in keyboard and move/hover mouse cursor on any (start or end) braces. It will automatically highlight, block area. - Keep (hold)
⌘
(command) button in pressed condition and click on highlighted area. It will enable quick menu popover window withFold
option. - Select
Fold
from menu list. It will fold your code and shows 3 dots, folding/covering entire block. - Now, to again unfold your code block, release
⌘
(command) button and click on 3 dots folding a 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"

- 77,632
- 48
- 245
- 261
-
1Your answer is good. But apple is bad to take away the `code folding ribbon` function. – Jason Yu Sep 28 '17 at 03:12
-
1Thanks for the animation, that makes it easy to understand. I don't see the right-click option in XCode 9.2, but the menu option and keyboard shortcut work fine so that's not a big deal. One tip for selecting the block of code is to double-click the top brace and it'll select to its matching bottom brace. – James Toomey Jan 18 '18 at 19:18
-
1I really needed that screenshot. That 'ribbon' is really hard to find – user3152459 Feb 28 '19 at 20:33
-
Really nice thanks. Sadly though seems like Fold All and Unfold All are no more. Also although this is very useful, this and the other answers do not answer the question posted. My advice would be to delete this answer and instead leave the other answers where you have copy pasted, e.g. https://stackoverflow.com/questions/40285997/xcode-swift-code-folding-collapse – Max MacLeod Aug 05 '21 at 10:29
The correct answer is in some of the comments (not in any of the answers, I don't think...
incidentally, the shortcut keys for this are here:
Judging from past answers, this must have changed over time. This is from Xcode 6.1.1.

- 451
- 6
- 13
For the sake of completeness,
Fold All ⌘⌥⇧← command+option+shift+left

- 18,665
- 21
- 103
- 138
-
Undocumented keyboard shortcut, but works perfectly. This should be marked as the correct answer. – jowie Mar 05 '15 at 10:44
I don't think so, there are some handy keyboard shortcuts though:
Fold ⌃⌘← control+command+left
Fold All ⌘⌥⇧← command+option+shift+left
Unfold ⌃⌘→ control+command+right
Unfold All ⌃U control+U
Fold Methods/Functions ⌃⌘↑ control+command+up
Unfold Methods/Functions ⌃⌘↓ control+command+down
Fold Comment Blocks ⌃⇧⌘↑ control+shift+command+up
Unfold Comment Blocks ⌃⇧⌘↓ control+shift+command+down
Focus Follows Selection ⌃⌥⌘F control+option+command+F

- 5,460
- 5
- 40
- 50

- 4,282
- 7
- 51
- 88
-
Hmmm, the keyboard shortcuts aren't showing up in firefox on Windows. The characterset with the command key symbol obviously doesn't exist. I'll follow up with text alternatives. – conorgriffin Mar 05 '10 at 16:24
-
1Changed in Xcode5, for example Fold all Methods/Functions is now command+shift+option+left. +1 though for helping me find this. – Matthew James Briggs Dec 28 '13 at 18:53
I feel your pain. It is difficult to press cmd+option+shift+left every time I open an implementation file to collapse all the methods. I would be grateful to know of a way to set this by default. On the other hand, a probably obvious workaround may be to select the method from the method picker at the top of the window. I suppose this is how the Xcode developers intended us to find methods.. still cmd+option+shift+left is my preference.. it just hurts my hand :/

- 1,345
- 2
- 14
- 17
-
Actually I just started settling with the picker, too :/ But that's mostly because Xcode also seems to become kinda buggy with long files and code folding :( – Infinite Aug 23 '11 at 10:58
-
Recently discovered that if you select the picker with the mouse you can start typing a method name and it filters the picker list by what you type. – geekinit Jul 28 '13 at 02:32