Hello, how can I pass data to a child component in SwiftUI? I want to pass a name to a child component but there is an error in the child component (I have uploaded an image which shows the error).
I have a parent component called Content_View:
struct ContentView: View {
@State private var name = "Eric"
var body: some View {
ZStack {
AnotherScreen(name: $name)
}
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
and a child component called AnotherScreen.
struct AnotherScreen: View {
@Binding public var name: String
var body: some View {
Text(name)
}
}
struct AnotherScreen_Previews: PreviewProvider {
static var previews: some View {
AnotherScreen(name: String)
}
}