12

Is anyone having problem with code folding in Xcode 8? Every time I fold GameScene.swift (or any other file), switch to, for example, AppDelegate.swift, and switch back to GameScene.swift (which were folded before), it unfolds.

Krunal
  • 77,632
  • 48
  • 245
  • 261
Luiz
  • 1,275
  • 4
  • 19
  • 35

2 Answers2

10

Xcode unfortunately neither store nor remembers code folding. It actually resets folded parts after losing focus that file.

Since the code folding is reset all the time, I personally use this way of refolding:

To fold all the methods: Shift + Alt + Cmd + <- left

Place cursor onto the desired method and unfold it by clicking or using shortcut: Alt + Cmd + -> right

pedrouan
  • 12,762
  • 3
  • 58
  • 74
  • but I'd always have to do it when losing focus. And it doesn't fold things inside the folded functions (a if condition, for example). – Luiz Sep 25 '16 at 17:28
  • It worked on the last Xcode version. Is that something to be fixed? Because I can't see where it helps the developer. – Luiz Sep 25 '16 at 17:29
  • It never worked for me, maybe it was able to remember some folded blocks of the code, not sure. Sadly said, I miss this feature working reliably, for many years. – pedrouan Sep 25 '16 at 17:33
  • It weirdly worked for me then, I don't know why. That might be something to report, so they fix/implement this. – Luiz Sep 25 '16 at 17:47
  • Feel free to report this, if they reply with any response, coming back and posting it here would be greatly appreciated :) – pedrouan Sep 25 '16 at 17:49
2

With Xcode-9, this issue is resolved. Code folding is being remembered and saved by Xcode 9 Editor.

Code you have/had folded exact before last source build/save, is automatically stored upon document/file closure. And same will be visible as it was (folded) when you will open document/file next time.

You don't need to do anything (there is no any option in Xcode tool bar to enable or disable) to save your code fold.


Here are some keyboard short cuts for code folding:

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
Krunal
  • 77,632
  • 48
  • 245
  • 261