GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

NavigationLink warning

Forums > 100 Days of SwiftUI

I have an issue with my first challenge. I've added a helpview:

      HStack {
                    NavigationLink(
                        destination: HelpView(),
                        isActive: $isShowingHelp,
                        label: {
                            Text("  Help  ")
                                .padding()
                                .background(Color.blue)
                                .foregroundColor(.white)
                                .cornerRadius(8)
                        }
                    )

Throws this warning:

 'init(destination:isActive:label:)' was deprecated in iOS 16.0: use NavigationLink(value:label:), 
 or navigationDestination(isPresented:destination:), inside a NavigationStack or NavigationSplitView                   

Works fine, tho. How can I fix this?

2      

Try this

struct ContentView: View {
    @State private var isShowingHelp = false

    var body: some View {
        NavigationStack {
            Button {
                isShowingHelp.toggle()
            } label: {
                Text("Help")
                    .padding()
                    .background(Color.blue)
                    .foregroundColor(.white)
                    .cornerRadius(8)
            }
            .navigationDestination(isPresented: $isShowingHelp) {
                HelpView()
            }
        }
    }
}

2      

Thanks for the reply,

Throws this error:

Closure containing a declaration cannot be used with result builder 'ViewBuilder'

Edit: Fixed! Thanks so much, I think I misapplied your fix, started from scratch and the error is gone.

2      

The code that above does not give any errors. So will be something esle.

2      

Go further, faster with the Swift Career Accelerator.

GO FURTHER, FASTER Unleash your full potential as a Swift developer with the all-new Swift Career Accelerator: the most comprehensive, career-transforming learning resource ever created for iOS development. Whether you’re just starting out, looking to land your first job, or aiming to become a lead developer, this program offers everything you need to level up – from mastering Swift’s latest features to conquering interview questions and building robust portfolios.

Learn more here

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.