Michael Long
1 min readAug 12, 2019

--

It’s pretty common in Swift/iOS to navigate to a view that shows a spinner, then data or an error, and that’s pretty easy to do in SwiftUI with conditionals inside of the body showing either a list or an error message based on the state of the results of the load. In fact, with NavigationLink that’s really the only way it can be done. NavigationLink WILL navigate to the next view when tapped.

The problem with SwiftUI lies in the fact that NavigationLink builds a value parameter (struct) for every item in the list, with all of the passed parameters and initialization said item might incur. What it should do is provide navigation link with a closure in which the item can be constructed when needed.

Though actually, what it should do is follow the Flutter model and provide access to an environment-based Navigator object whereby push/pop/present events can be better controlled.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

No responses yet