Search code examples
swiftswiftuiswiftui-navigationlink

Is there a way to supply a boolean statement in the isActive parameter within NavigationLink in SwiftUI?


I'm trying to get a NavigationLink to trigger when a string is no longer nil. Is there anyway to do this or something similar?

NavigationLink(destination: MainView(), isActive: $settings.isLoggedS !=nil)

Any help is greatly appreciated!


Solution

  • You can program the link.

              @State var activeString : String = ""
              var body: some View {
                NavigationView{
                    NavigationLink(destination: Text(""), isActive: Binding<Bool>(get: {self.activeString != ""}, set: { _ in
                    }) ){
                        TextField("input", text: $activeString)}}}