is it possible to call a func of a View from outside.
I tried like this, but had no success.
@main
struct CallFromOutsideApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
var body: some View {
VStack{
SubView()
Button("Call alterX in ContentView"){
// How to call alterX in SubView????
}
}
.padding()
}
}
struct SubView: View {
@State var x = "Status A"
var body: some View {
VStack{
Text("Status: \(x)")
Button("Call alterX in SubView"){ alterX()
}
}
.padding()
}
func alterX(){
x = "Status B"
}
}