skip to Main Content

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.)

2

Answers


  1. 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).

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search