Code Folding changes in Xcode 9/10 [duplicate]
Asked Answered
S

3

23

I know code folding was missing in the early Beta's of Xcode9 and that it is available to fold entire methods with CMD click.

But in Xcode 8 i was able to fold code in blocks (i.e. individual if statements) via Editor >> Code Folding >> Fold but in Xcode 9 this folds the entire method.

Is there a fix/setting i can change to restore the Xcode 8 functionality?

Stavro answered 24/9, 2017 at 6:27 Comment(0)
S
9

It is stated in the release notes that it is not supported as of yet.

Sp answered 27/9, 2017 at 22:42 Comment(4)
Ya got to be kidding. Who comes up with the idea of dropping code folding after having supported it for decades and it being used all day every day by every developer that's ever developed. Prediction: Due to the advent of retina displays Apple will render every file as a single page even if it drives the font down to 1pt so as to encourage developers to write smaller more sophisticated files written in a brand new language (that will change its syntax dramatically by EOD tomorrow and break your app).Mendiola
Xcode 9 is a total Swift re-write. Code-folding will return ;)Sp
lol. Ok great. I hope you enjoyed my rant. It's easy to work around and I'm all for progress.Mendiola
Sure did @JohnErck -check out devrant.io btw :DSp
N
55

Updates in Xcode 10

Xcode 10 has increased support for code folding, including:

  1. A new code folding ribbon showing all of the multi-line foldable blocks of code in the editor
  2. A new style for folded code in the editor that allows you to edit lines with folded code
  3. Support for folding any block of code enclosed in curly braces
  4. Support for folding blocks of code from the folding ribbon, from structured selection, or from the

Menubar ► Editor ► Code Folding ► Fold menu item

enter image description here

Look at this snapshot:

enter image description here


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:

  1. Press and hold (command) button in keyboard and move/hover mouse cursor on any (start or end) braces. It will automatically highlight, block area.
  2. Keep (hold) (command) button in pressed condition and click on highlighted area. It will enable quick menu popover window with Fold option.
  3. Select Fold from menu list. It will fold your code and shows 3 dots, folding/covering entire block.
  4. 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:

enter image description here


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:

enter image description here

Same options from Xcode Short-cut list:

Menubar ▶ Xcode ▶ Preferences ▶ Key Bindings ▶ "Here is list of code folding short-keys"

enter image description here

Natator answered 6/10, 2017 at 9:51 Comment(5)
Thanks for the detailed response. However as stated in the question I am aware of how to fold entire methods. I am looking to see if the old functionality of folding blocks within methods was still available.Stavro
@Stavro Same question for me. I am missing the old feature, the graphical way to do it.Prepossession
Would have been better if given an arrow on left of file to fold, unfold braces blocksFleisher
@Fleisher - Unable to get you. Please dictate. You are welcomed to improve this answer by sharing your inputs.Natator
Finally they got it back!Henni
S
9

It is stated in the release notes that it is not supported as of yet.

Sp answered 27/9, 2017 at 22:42 Comment(4)
Ya got to be kidding. Who comes up with the idea of dropping code folding after having supported it for decades and it being used all day every day by every developer that's ever developed. Prediction: Due to the advent of retina displays Apple will render every file as a single page even if it drives the font down to 1pt so as to encourage developers to write smaller more sophisticated files written in a brand new language (that will change its syntax dramatically by EOD tomorrow and break your app).Mendiola
Xcode 9 is a total Swift re-write. Code-folding will return ;)Sp
lol. Ok great. I hope you enjoyed my rant. It's easy to work around and I'm all for progress.Mendiola
Sure did @JohnErck -check out devrant.io btw :DSp
C
7

You can fold individual if statements also in Xcode 9 however it folds the entire if - (else) expression.

Put the cursor somewhere within the block and press ⌥⌘←

Unfolded:

enter image description here

Folded:

enter image description here

Cogswell answered 24/9, 2017 at 6:43 Comment(7)
that still folds the entire method.Stavro
Don't select anything, just put the cursor somewhere between the if and the closing } of the affected block. See the edited answer.Cogswell
I am working in objective C would that make a difference? Because no matter wear i put the curser the entire method folds.Stavro
It could be that Objective-C behaves differently, I regard it as a bug. In Swift it works as described.Cogswell
I don't like the change....Tinstone
Why do Apple insist on fixing what isn't broken?Semiliterate
but in object-c ,it not supportYellowwood

© 2022 - 2024 — McMap. All rights reserved.