'Xcode: Button action between files/views

Xcode complete beginner

Trying to make searchbar appear in different view than where the button is placed. When pressing magnifying-glass (button placed in ContentView), I want the text to appear in FeedView. How? @Published/ObservedObject/State...?? I have no knowledge just like to play around and learn. So 1. press magnifying-glass 2. makes the text appear (needs to be in different views)

ContentView:

import SwiftUI

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

    var body: some View {
       
        Button {
            doSearch.toggle()
        } label: {
            Image(systemName: "magnifyingglass")
                .foregroundColor(Color(.black))
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

FeedView:

import SwiftUI

struct FeedView: View {
    @State private var doSearch = false

    var body: some View {
        HStack {
            if doSearch {
                Text("search bar here")

            }
        }
    }
}

Images:

ContentView

FeedView



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source