2

I like to work with code folding by using option + command + right or left key bindings. It is appearing to me more readable at first glance, especially for long classes.

Let me explain with an example, suppose we have a class:

func someFunction(input: String) -> Bool {
    // if you click command option left arrow , case 1 
    ...
}

func someFunction(input: String) -> Bool {} // it is being like this, case 2. Perfect.

//MARK - Properties
var x: String = "a"
var y: Int = 3
var z: Double = 3.0 // the property list could be longer,

properties: i want to see something like this, at least at one line but but could not find a way

This is okay for methods or class as they have {}, but what about properties? Is there a way of folding them in the same way or a tricky way? (But I don't want to affect my code performance as well.)

TylerP
  • 9,600
  • 4
  • 39
  • 43
zeytin
  • 5,545
  • 4
  • 14
  • 38
  • 2
    I think the term you're looking for is "code folding" instead of "squeezing/extending". And no, I don't think there's currently a way to fold just the properties. – TylerP Jan 26 '21 at 19:35
  • 2
    @Tyler thanks i edited my question, looks like no way but maybe someone has idea or a good suggestion :) – zeytin Jan 26 '21 at 19:42
  • 2
    This would be nice, though if you have so many properties, it's a good indication your object is too big :p – Alexander Jan 26 '21 at 19:54

2 Answers2

3

I'm afraid the best you can do is to move the properties off into another type (i.e. a struct). You can keep that struct definition in another file or, if it is in this file, you can fold that:

enter image description here

Imagine there are 100 properties; they would all be inside the Props struct and could be declared in another file or, as in the screen shot, hidden by folding.

Making a sequence of properties foldable sounds like a reasonable enhancement request but I doubt it would actually happen; I've never seen an IDE that does this (though I don't get out much so who knows, maybe such a thing exists).

matt
  • 515,959
  • 87
  • 875
  • 1,141
1

As of Xcode 12 there is no way to do this. Editor > Fold Methods & Functions (⇧ ⌥ ⌘ ←) will not fold properties.

The best you can do is put the cursor on each unfolded property and choose Editor > Code Folding > Fold (⌥ ⌘ ←).

I guess Apple is trying to strongly suggest that developers use properties sparingly? It's ridiculous that this isn't an option.

spnkr
  • 952
  • 9
  • 18