Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code folding in Xcode 8

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.

like image 985
Luiz Avatar asked Sep 25 '16 15:09

Luiz


People also ask

Can you collapse functions in Xcode?

Just to the right of line numbers you will see a new ribbon with up or down arrows next to functions / methods. Pressing these will allow you to expand or collapse functions / methods.

How do you collapse code in Swift?

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.


2 Answers

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

like image 199
pedrouan Avatar answered Sep 26 '22 02:09

pedrouan


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
like image 24
Krunal Avatar answered Sep 25 '22 02:09

Krunal