Recreating Navigation Destination (item:destination:) For iOS 16

Getting around iOS 17-only limitations with custom bindings.

Michael Long
The Swift Cooperative

--

Photo by Dan Asaki on Unsplash

So I’m working on a SwiftUI project and once more I run across the bane of the SwiftUI developer’s existence. You know the one. You type in some code and all of a sudden you see:

navigationDestination(item:destination:)’ is only available in iOS 17.0 or newer

I’m fortunate in that the project I’m working on has iOS 16 as the minium supported version, but that’s it. There’s no way we could bump the minimum up to iOS 17 just so I could use a single view modifier.

Now I could go off on yet another rant regarding Apple’s stupidity in tying SwiftUI library versions to iOS release versions, but I’ve said it before and while it might make me feel better (for a few minutes, anyway), that’s not going to solve my immediate problem.

So I thought about it for a few minutes, took a break… and then suddenly realized that I could probably recreate that modifier on my own.

Using a little-known feature of SwiftUI.

Let me explain, starting with…

What is .navigationDestination(item:destination:) ?

--

--

Michael Long
The Swift Cooperative

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.