Code folding in Xcode 8
Asked Answered
M

2

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.

Mayhap answered 25/9, 2016 at 15:42 Comment(0)
O
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

Ozonide answered 25/9, 2016 at 16:23 Comment(5)
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).Mayhap
It worked on the last Xcode version. Is that something to be fixed? Because I can't see where it helps the developer.Mayhap
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.Ozonide
It weirdly worked for me then, I don't know why. That might be something to report, so they fix/implement this.Mayhap
Feel free to report this, if they reply with any response, coming back and posting it here would be greatly appreciated :)Ozonide
A
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
Ammonia answered 3/10, 2017 at 17:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.