UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Ultimate Portfolio App - How to replace the deprecated "init(destination:tag:selection:label:)" in video 37 "Integrating with spotlight"?

Forums > SwiftUI

Hi everyone,

I encountered an error at the part of the video where Paul adds this code :

if let item = viewModel.selectedItem {
    NavigationLink(
        destination: EditItemView(item: item),
        tag: item,
        selection: $viewModel.selectedItem,
        label: EmptyView.init
    )
    .id(item)
}

It says it's been deprecated and also says how to replace it, but I don't understand. Can someone help me replace it using the new Xcode 14.1 API please?

Thank you in advance!

1      

Having this issue as well. Using NavigationLink(value: , label: ) does not give me the result I'm looking for.

1      

I found this works

  @State var selection: String = "Overview"
    @State private var columnVisibility = NavigationSplitViewVisibility.doubleColumn

    var body: some View {

        NavigationSplitView(columnVisibility: $columnVisibility) {

                List(selection: $selection) {
                    Section("Installer Section")
                    {
                        NavigationLink( value: "Overview")
                        {
                            Label("Overview" , systemImage: "square.grid.3x1.folder.fill.badge.plus")
                        }
                        NavigationLink( value: "Welcome")
                        {
                            Label("Welcome" , systemImage: "square.grid.3x1.folder.fill.badge.plus")
                        }
                        NavigationLink( value: "Contents")
                        {
                            Label("Contents" , systemImage: "square.grid.3x1.folder.fill.badge.plus")
                        }
                        NavigationLink( value: "Thanks")
                        {
                            Label("Thanks" , systemImage: "square.grid.3x1.folder.fill.badge.plus")
                        }
                    }
                    Divider()
                    NavigationLink( value: "Settings")
                    {
                        Label("Settings" , systemImage: "gear")
                    }
                }

        } detail: {

            if selection == "Overview" {
                Overview()
            } else if selection == "Welcome" {
                WelcomeView()
            }else if selection == "Contents" {
                ContentsView()
            }else if selection == "Thanks" {
                ThanksView()
            }else if selection == "Settings" {
                ContentView()
            }

        }
        .navigationSplitViewColumnWidth(min: 150, ideal: 250, max: .none)

1      

This is not really the solution to the question asked imho. I am struggling as well on how to push the navigation stack to EditItemView(item: item) using the new signature for NavigationLink automatically while not messing up the HomeView....

1      

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.