TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 {
                        Image(mission.image)
                            .resizable()
                            .scaledToFit()
                            .frame(width: 100, height: 100)

                        VStack {
                            Text(mission.displayName)
                                .font(.headline)
                            Text(mission.launchDate ?? "N/A")
                                .font(.caption)
                        }
                        .frame(maxWidth: .infinity)
                    }
                }
            }
        }
    }
    .navigationTitle("Moonshot")
}

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.

1      

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.

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.