I want push and post a text to next screen when tapping on Button. But NavigationLink need @state property to catch data. How to avoid this? I hope there is a way I only handle data in button action.
Code Block Swift @State var selection: Int? = nil @State var text: String? = nil var body: some View { VStack(content: { HStack(alignment: .center, spacing: nil, content: { NavigationLink(destination: Drawing(text: text), tag: 1, selection: $selection) { Button("complete", action: { print(self.selection) print(self.text) self.text = "hello" self.selection = 1 }) } }).padding()
Seems the best way for you is to go back to the UIKit world.I think this is a bit difficult to understand compared with the commonly used implementation. For example, It's does not need set some property in UIViewController for post data to next UIViewController when tap a button.