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

SOLVED: NavigationLink(label:, value:)

Forums > SwiftUI

I see this "new" NavigationLink in Apples documentation:

Apple NavigationLink

I am upgrading my working code from using a depreciated NavigationLink with "destination" to using a NavigationStack with a value.

But, I can not get XCode to accept any syntax I can come up with using a Label ().

Here is what I have tried (along with otheer variations). XCode chokes on this and says it is too complex - sigh.

NavigationLink( value: sidebar, { Label(sidebar.title, systemImage: SFSymbolsModel.icon[sidebar.type] ?? "questionmark" ) })

I need a Label (I think - it is what I used before) because I want to format the displayed text with an Icon.

Can anyone provide a one or two line example for me?

2      

value must be Hashable and Codable so sidebar need to that Here a simple one

struct ContentView: View {
    var body: some View {
        NavigationStack {
            NavigationLink(value: "❤️") {
                Label("Heart", systemImage: "heart.fill")
                    .symbolRenderingMode(.multicolor)
            }
            .navigationTitle("Navigation Demo")
            .navigationDestination(for: String.self) { stringValue in
                Text(stringValue)
            }
        }
    }
}

3      

Thank you, appreciate it.

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your 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.