6

I have a basic list in my first View as Follows:

func buildList(sections: [Client]) -> some View {
    let list = List {
        ForEach(sections) { client in
            Section(header: Text(client.name)) {
                ForEach(client.projects) { project in
                    NavigationLink(destination: BuildsRouter.build(forProject: project)) {
                        HStack {
                            Text("Test \(project.id)").fontWeight(.ultraLight)
                        }
                    }
                }
            }
        }
    }
    return  list
}

I'm using NavigationLink to provide the details view for my Project object.

Thing is, when I make a Memory analysis graph I can see that BuildsView ( created from BuildsRouter.build(forProject: project) are created before I actually tap the navigation Link.

Question: Is there any way to create the details View once the link is tapped?

1

1 Answer 1

4

True, I wrote a blog post on this. You can wrap the destination views in a Lazy Container as a workaround. Update: From Xcode 11.4.1 NavigationLinks are lazy by default.

Sign up to request clarification or add additional context in comments.

5 Comments

I don't think this is true. I am on Xcode 11.4.1 and NavigationLink Destination Views are being loaded at App start up.
Strange, is the iOS version 13.4.1 or above as well?
Yep. It is not in every case either, some NavigationLInks are loading at App startup and some are being lazy loaded, I'm yet to determine the pattern. I am using the objc.io solution to fix this at the moment.
Even if it's fixed in 11.4.1, does this mean we need to wrap all NavigationLink views in lazy loading wrappers since lower versions of iOS 13 on devices would still have this issue?
I'd recommend wrapping them in Lazy as the issue popped up again in 11.5

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.