UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Easier way to find matching braces?

Forums > 100 Days of SwiftUI

I searched online for this first. But, oddly there's not a lot of info online about xcode it seems. Or, I can't find it yet. And Apple's docs are so cryptic. It reminds me of legal-ese.

Anyway, I've been having to resort to an old trick to keep track of my closing braces using comments:

}// End main VStack

}// End ZStack

I see that it flashes the matching brace briefly when one is selected. But, that only works if you can see both at the same time, and code gets long.

How do you guys do it? Thanks

2      

If you doubleclick on the ending brace it will highlight the entire block back to the opening brace.

3      

@mark reveals some tough times with the Google...

I searched online for [...find matching braces] first. But, oddly there's not a lot of info online about xcode it seems.

You had bad luck searching for the wrong string!

Instead, try searching for: Xcode code folding

This is a great shortcut a number of Xcode presenters use in their vids.

Code Folding

Place your cursor inside a VStack, ForEach group, Button, function, class, or anything delimited by brackets. Then hold Option-Command-LeftArrow. aka ⌥ ⌘ ⬅️

This will fold the code showing just the starting and ending brackets with three ellipses inbetween.

     // Example of folded code
     VStack{ ... }  // end of VStack

     // or
     struct DeleteExpenseView: View  { ... }  // <-- folded view struct

As you may guess, Option-Command-RightArrow expands a folded code group.

Keep Coding!

3      

Thanks @Legion, and man do I feel a little silly now. I could have sworn I already tried double clicking it. ha

This code folding looks nice too. Other IDEs do this but I never felt the need to hide anything. Maybe I should try to find a use for it since it seems so useful. Thanks @Obelix

2      

@mark wonders about code folding:

Other IDEs do [folding] but I never felt the need to hide anything.
Maybe I should try to find a use for it since it seems so useful.

You were looking for ways to find matching braces.
Quite literally, the closing brace is three dots away from the opening brace after folding!

2      

@Bnerd  

Code folding is a life saver when optimizing the code and you know that you are done with one part..

2      

I'd so much rather have colorized matching braces etc. as with VSCodium. I don't want my code folded, and don't want it obscured by highlighting. I just want to scan for matching colors, which, for my eyes, are much more findable.

Really not possible?

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.