NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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!

   

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

   

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)

   

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

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.