SwiftUI pIcker View to view

I have created a simple picker of String options. I know the users pick is stored in chosenValue

@State var valuesAvail = ["hey","hello",how y'all","howdy"," aloha"]
var chosenValue = "hey

I would like to use the chosenValue as the title of my next screen.
I thought since it was stored in chosenValue I could simply @ and use it but I can not get it to work and I know I must be missing something so simple, so I'm asking for help please.

Have you tried to add @Binding in your "next screen"?

struct NextScreen: View {
  @Binding chosenValue: String

  var body: some View {
    Text(chosenValue)
  }
}

Then in your current view you can do

struct CurrentView: View {
  private var valuesAvail = ["hey","hello","how y'all","howdy"," aloha"]
 
  @State private var chosenValue = "hey"

  var body: some view {
    NextScreen(chosenValue: $chosenValue)
  }
3 Likes