Xcode, Fold group of codes under certain method/ function with a simple click

I Have a multiple if else statements under another if else statements and I want to be able to fold all child statements under certain parent without have to fold each one separately cause its like 100's of them example:

This Is Unfolded

    func example(v1: String, v2: Int, v3: Int)
    {
        if v1 == "Food"
        {
            if v2 == 2 && v3 == 7
            {
                // Some Long Lines Codes
            }
            else if v2 == 2 && v3 == 33
            {
                // Some Long Lines Codes
            }
            else if v2 == 44 && v3 == 72
            {
                // Some Long Lines Codes
            }
            else if v2 == 12 && v3 == 7
            {
                // Some Long Lines Codes
            }
            else if v2 == 102 && v3 == 97
            {
                // Some Long Lines Codes
            }
        }
    }

And I Wanted To Be Folded Like That With A Simple Click Not Fold It One By One

    func example(v1: String, v2: Int, v3: Int)
    {
        if v1 == "Food"
        {
            if v2 == 2 && v3 == 7
            {...}
            else if v2 == 2 && v3 == 33
            {...}
            else if v2 == 44 && v3 == 72
            {...}
            else if v2 == 12 && v3 == 7
            {...}
            else if v2 == 102 && v3 == 97
            {...}
        }
    }

Imaging like 100 lines of those else if conditions that i need to fold each one manually using CMD + Opt + <- or even using the arrow beside, I hope there is a fast and reliable shortcut or a click to help folding child codes or selected codes

btw I know there is a cmd + opt + shift + <- to fold all but that's not helping cause when I unfold the function I would see all remains as it was before.

I hope anyone could have a clue or if there is an ability to add a script function to do so.

Replies

I don't have such a script.

But in this case, I usually write func for each long lines code:

func v2_2_v3_7() {  &#x2F;&#x2F; You should select a more meaningful name…
   &#x2F;&#x2F; Some Long Lines Codes
}

and call

   if v2 == 2 &amp;&amp; v3 == 7  { v2_2_v3_7()  }

I find it improves readability dramatically.

Sorry I may have not expressed the question well, I'm not asking about this certain code, this codes are just a generic sample and it could be anything else, I'm asking about if this possible or not in Xcode cause so far until Xcode 14.3 it does not seem to happen and it is as simple as fold all Childs under one parent or fold all selected only ,may be apple could notice that and may be like to add it on the next update cause it really helps specially for 3D Physics Collision with different actions.