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!

2      

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

2      

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)

2      

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

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.