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

SOLVED: Keeping track of nesting depth in views

Forums > SwiftUI

Is there a simple way to keep track of depth in deeply nested brackets in SwiftUI views?

For example, in this code from the Missions project, I'm struggling to keep track of which closing brackets are for which views.

NavigationStack {
    ScrollView {
        LazyVGrid(columns: columns) {
            ForEach(missions) { mission in
                NavigationLink {
                    Text("Detail view")
                } label: {
                    VStack {
                            .frame(width: 100, height: 100)

                        VStack {
                            Text(mission.launchDate ?? "N/A")
                        .frame(maxWidth: .infinity)

I have noticed when moving the cursor to one of the brackets, the other will flash yellow, but often the height of the distance between the two brackets is too tall for the editor's view. I'm used to other text editing tools to have collapeable brackets, but I haven't found that feature yet. Thanks for any and all suggestions on making this easier to deal with than getting out a straight edge and holding it up to the screen as I scroll down.

As I go through 100 Days of SwiftUI, I have a feeling I'll learn to keep View types smaller with less nesting, but in the meantime or while working on code before refactoring.


If you put your cursor by a top bracket you can use Cmd + Option + left arrow to close the bracket. You'll then have an ellipses you can double click to reopen the bracket or Cmd + Option + right arrow also reopens it.


Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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.